试图安装SPJobDefinition;没有出现在列表中

时间:2009-06-24 20:48:40

标签: sharepoint-2007

我正在尝试关注http://msdn.microsoft.com/en-us/library/cc406686.aspx和类似的教程。我有一个自定义SPJobDefinition衍生物和一个功能。该定义还没有做任何事情,因为我只是想设置它。该功能在FeatureActivated中具有以下代码:

        // 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();

我错过了什么?它都可以正常部署,并且该功能可以很好地激活,但它不会显示在作业定义列表中!

4 个答案:

答案 0 :(得分:1)

这是我在部署timerjob时使用的代码,区别在于我正在部署到Web应用程序,您到网站集(我假设您的功能是Scope Site):

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();}

答案 1 :(得分:1)

每次更新代码后,您不仅需要将DLL部署到GAC中,还需要重新启动“SharePoint 2010 Timer”服务。

答案 2 :(得分:0)

我实际忘记将功能接收器信息添加到feature.xml中,因此该功能正在激活,但计时器作业未显示。

我遇到了另一个问题 - 计时器作业在运行时没有做任何事情,无论我把它放入执行代码中。

答案 3 :(得分:0)

您需要将dll与计时器作业定义(执行等)部署到GAC(C:\WINDOWS\assembly