views:

656

answers:

3

I'm trying to follow http://msdn.microsoft.com/en-us/library/cc406686.aspx and similar tutorials. I've got a custom SPJobDefinition derivative and a feature. The definition doesn't do anything yet, since I'm just trying to get it setup. The feature has the following code in the 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();

What am I missing? It all deploys fine, and the feature activates fine, but it doesn't show up in the list of job definitions!

+1  A: 

Here's the code i use when deploying a timerjob, the difference is is that i am deploying to a web application, you to a site collection (i assume your feature is of 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();}
Colin
A: 

I actually forgot to add the feature receiver information into the feature.xml, so the feature was activating, but the timer job was not showing up.

I ran into another problem, though - the timer job doesn't do anything when it runs, no matter what I put into the Execute code.

A: 

you need to deploy the dll with the timer job definition (execute etc.) to the GAC (C:\WINDOWS\assembly)

Hello

related questions