私はこのように私のタイマージョブを書いた:それはあなたが全体管理であなたの仕事を見ることができます最終的にはイベントレシーバー
[Guid("46b3a9b4-793e-4ab9-99ba-b003a3601e3a")]
public class MainEventReceiver : SPFeatureReceiver
{
public static string JOB_NAME = "YourJobName";
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parent as SPSite;
// Make sure the job isn't already registered.
foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
{
if (job.Name == JOB_NAME)
job.Delete();
}
YourJob job = new YourJob(site.WebApplication);
job.Update();
}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parent as SPSite;
// Delete the job.
foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
{
if (job.Name == JOB_NAME)
job.Delete();
}
}
}
を特徴とするジョブを追加する必要が
public class YourJob : SPJobDefinition
{
private static string JOB_NAME = "YourJobName";
public override string Description
{
get
{
return "YourDescription";
}
}
public YourJob() : base() { }
public YourJob(SPWebApplication webApp)
: base(JOB_NAME, webApp, null, SPJobLockType.None)
{
this.Title = JOB_NAME;
this.Schedule = GetSchedule();
}
//This job start to run every day between 00:00 to 00:30
//There are several options
private SPSchedule GetSchedule()
{
SPDailySchedule myDailySchedule = new SPDailySchedule();
myDailySchedule.BeginHour = 00;
myDailySchedule.BeginMinute = 00;
myDailySchedule.BeginSecond = 0;
myDailySchedule.EndHour = 00;
myDailySchedule.EndMinute = 30;
myDailySchedule.EndSecond = 0;
return myDailySchedule;
}
public override void Execute(Guid targetInstanceId)
{
//Write here your code.
//In this example we get value from SP (in every zone) web config to do something with it.
foreach (SPUrlZone urlZone in Enum.GetValues(typeof(SPUrlZone)))
{
if (((SPWebApplication)this.Parent).IisSettings.ContainsKey(urlZone))
{
var zone = ((SPWebApplication)this.Parent).IisSettings[urlZone];
var appName = zone.ServerComment;
var WebConfigKey = GetAppSettings(appName, "WebConfigKey");
}
}
}
private string GetAppSettings(string appName, string Key)
{
string result = String.Empty;
SPWebApplication webApplication = this.Parent as SPWebApplication;
Configuration config = WebConfigurationManager.OpenWebConfiguration("/", appName);
if (config.HasFile && config.AppSettings.Settings[Key] != null)
{
result = config.AppSettings.Settings[Key].Value;
}
return result;
}
}
後 - >監視 - >タイマージョブ - ジョブ定義を確認します。ここでスケジュール定義をリセットすることができます。
おかげで、リッチ:
ので、カスタム記述を持つために、あなたは次のようにカスタムジョブ定義を定義する必要があります。
SPJobDefinitionのDescriptionプロパティは、次のように実装されています。前のリンクのソリューションも実際には機能しています。私が持っていた問題は、時代遅れのジョブ定義オブジェクトで構成されていました。私はVisual Studioで適切なソリューションを取り戻そうとしましたが、SharePoint Timerサービスを再開しましたが、何の助けにもなりませんでした。問題を近づけたという決定は、PowerShellでソリューションをアンインストールして削除することでした。最後に、私は自分の仕事の定義に新しい記述を見ることができました。 – Deniplane