Home > SharePoint, timer job > Prevent SharePoint Timer Jobs from running multiple times

Prevent SharePoint Timer Jobs from running multiple times


You developed a timer job and deployed it to your SharePoint farm. The timer job was supposed to send one email but you get more than one…what is wrong here???

The timer job is working fine and the results are fine, but only thing is that it running multiple times…

This is a common scenario people face when they develop and deploy a timer job in a SharePoint farm

The solution is setting SPJobLockType to Job

SPJobLockType.None – The timer job runs on every machine in the farm on which the parent service is provisioned, unless the job I associated with a specified server in which case it runs on only that server (and only if the parent service is provisioned on the server).

SPJobLockType.ContentDatabase – Locks the content database. A timer job runs one time for each content database associated with the Web application.

SPJobLockType.Job – Locks the timer job so that it runs only on one machine in the farm.

/// 
/// Constructor
///

public StatusEmailTimerJob(string jobName, SPWebApplication webApplication,SPSite site)
: base(jobName, webApplication, null, SPJobLockType.Job)
{
Title = "StatusEmailTimerJob";
}
Advertisements
Categories: SharePoint, timer job
  1. No comments yet.
  1. No trackbacks yet.

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 )

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 )

w

Connecting to %s

%d bloggers like this: