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";

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.