MOSS 2007 Timer Jobs

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


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.


    // 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
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.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s