MOSS 2007 Timer Jobs

SharePoint Timer service is similar to Windows Task or Windows Services.
Time job inherits from

Microsoft.SharePoint.Administration.SPJobDefinition

using System;
using System.Net;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace MKS.Demo {
  public class TestTimerJobs : SPJobDefinition {

    public TestTimerJobs() : base() { }

    public TestTimerJobs(SPWebApplication webApp)
      : base(Globals.JobName, webApp, null, SPJobLockType.ContentDatabase) {
      this.Title = Globals.JobName;
    }

public TestTimerJobs(string TimerName , SPWebApplication webApp)
      : base(TimerName , webApp, null, SPJobLockType.ContentDatabase) {
      this.Title = TimerName ;
    }

  }
}

There are three different types of locking,

  • SPJobLockType.ContentDatabase Locks the content database associated with the job.
  • SPJobLockType.Job Locks the job to prevent multiple instances of the job from running on a single server.
  • SPJobLockType.None No locking.

Override the Execute virtual method defined in the SPJobDefinition.

public override void Execute (Guid targetInstanceId)
{
//Write your custom Logic here.
}

Compile the DLL and place it into GAC.

Deploymet


    // Get the object of TestTimerJobs what is deployed in GAC
    TestTimerJobs taskLoggerJob = new TestTimerJobs("TEST TIMER JOB", site.WebApplication);
    SPMinuteSchedule schedule = new SPMinuteSchedule();
    schedule.BeginSecond = 0;
    schedule.EndSecond = 59;
    schedule.Interval = 5;
    TestTimerJobs.Schedule = schedule;
    //update the job
   TestTimerJobs.Update();
BeginSecond and EndSecond specify that timer job can start
randomly in between.

Interval is a 32-bit integer that specifies the interval in minutes. The default value is 5.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s