2011-11-02 64 views
2

我想部署一個自定義的SPJobDefinition,我想針對特定的Web應用程序運行。我認爲我可以通過使用SPJobDefinition的Web應用程序範圍基礎構造函數並傳入我想要的Web應用程序。我在一家網絡應用特徵的FeatureActivated事件接收器這樣做:針對特定Web應用程序的SharePoint計時器作業?

  TestJob Job = new TestJob("Test", webApp); 
      // TODO: change the schedule to run nightly; one time for testing purposes only 
      SPOneTimeSchedule schedule = new SPOneTimeSchedule(DateTime.Now); 
      TestJob.Schedule = schedule;     
      TestJob.Update(); 

下面是工作本身的構造:

public TestJob(string jobName, SPWebApplication webApplication) 
     : base(jobName, webApplication, null, SPJobLockType.Job) 
    { 
     this.Title = jobName; 
    } 

看來,在不考慮對所有Web應用程序運行的工作。有什麼建議麼?

回答

1

出現小錯誤:您需要投射您的定時作業定義而不是您的自定義ChangeRequestRollup

所以做你的功能接收以下內容:

SPJobDefinition changeRequestRollupJob = new ChangeRequestRollup("Devon PMO Change Requests Report", webApp); 
// install timer job, on a daily scheduleSPDailySchedule dailySchedule = new SPDailySchedule 
{ 
    BeginHour = 07, 
    BeginMinute = 11, 
    BeginSecond = 00, 
    EndHour = 09, 
    EndMinute = 12, 
    EndSecond = 00 
}; 

changeRequestRollupJob.Schedule = dailySchedule; 
changeRequestRollupJob.Update(); 

我也不清楚自己的SPOneTimeSchedule所以我修改它使用SPDailySchedule。除此之外,它應該像你一樣做得很好。

相關問題