2009-06-24 35 views
1

我正在嘗試關注http://msdn.microsoft.com/en-us/library/cc406686.aspx以及類似的教程。我有一個自定義SPJobDefinition派生和一個功能。該定義還沒有做任何事情,因爲我只是試圖讓它安裝。該功能在FeatureActivated中具有以下代碼:試圖安裝SPJobDefinition;沒有顯示在列表中

 // Get the Site Collection in which this is being activated 
     SPSite siteCollection = (SPSite)properties.Feature.Parent; 

     // Make sure the job isn't already registered 
     foreach (SPJobDefinition jobDefinition in siteCollection.WebApplication.JobDefinitions) 
      if (jobDefinition.Name.Equals(TIMER_JOB_NAME)) 
       jobDefinition.Delete(); 

     // Create the job 
     Form40EscalationTimer timerJob = new Form40EscalationTimer(
       TIMER_JOB_NAME, 
       siteCollection.WebApplication, 
       null, 
       SPJobLockType.Job 
      ); 
     SPMinuteSchedule schedule = new SPMinuteSchedule(); 
     schedule.BeginSecond = 0; 
     schedule.EndSecond = 59; 
     schedule.Interval = int.Parse(ConfigurationManager.AppSettings["Form40EscalationJobIntervalMinutes"]); 
     timerJob.Schedule = schedule; 
     timerJob.Update(); 

     // Install the job - not here originally, tried from http://www.codeguru.com/cpp/misc/misc/microsoftofficeoutlook/print.php/c14133__1/ 
     siteCollection.WebApplication.JobDefinitions.Add(timerJob); 
     siteCollection.WebApplication.Update(); 

我錯過了什麼?它全部部署良好,並且該功能可以正常激活,但它不會顯示在作業定義列表中!

回答

1

這裏的部署timerjob當我使用的代碼,所不同的是是,我部署到Web應用程序,網站集(我假設你的特點是範圍網站):

public override void FeatureActivated(SPFeatureReceiverProperties properties) 
{ 
    SPWebApplication application = properties.Feature.Parent as SPWebApplication; 

    // make sure the job isn't already registered 
    foreach (SPJobDefinition job in application.JobDefinitions) 
    { 
    if (job.Name == ARCHIVE_JOB_NAME) 
     job.Delete(); 
    } 

    // install the job 
    NewsArchiverTimerJob archiveJob = new NewsArchiverTimerJob(ARCHIVE_JOB_NAME, application); 

    SPMinuteSchedule schedule = new SPMinuteSchedule(); 
    schedule.BeginSecond = 0; 
    schedule.EndSecond = 59; 
    schedule.Interval = 30; 

    archiveJob.Schedule = schedule; 

    archiveJob.Update();} 
0

我實際上忘了將特徵接收器信息添加到feature.xml中,因此該功能正在激活,但計時器作業未顯示出來。

但是,我遇到了另一個問題 - 計時器作業在運行時不會執行任何操作,無論我將其放入執行代碼中。

0

您需要部署dll與計時器作業定義(執行等)到GAC(C:\WINDOWS\assembly

1

每次更新你不僅需要部署DLL到GAC的代碼後,又重新啓動'SharePoint 2010計時器'服務。

相關問題