SharePoint 2010 ECM Code Sample: Pausable Timer Job

Use this SharePoint code sample to learn how to use the SPAllSitesJobDefinition object to pause or resume a timer job at the site collection level.

Applies to: SharePoint Server 2010

The Pausable Timer Job sample in the PausableAtCustomTimerJobScope.zip file is located in the path C:\Program Files\Microsoft SDKs\SharePoint 2010\Samples. This sample supports pausing or resuming a timer job at a custom level that is more granular than the list level, but less granular than the item level.

The sample demonstrates the SPAllSitesJobDefinition object, which supports pausing or resuming at the site-collection level. However, if the timer job can take a long time (for example, several hours) to process one site collection, it might never complete because the farm administrator may allow the job to run for only a few hours each night.

Download the SharePoint 2010 sample code described in this topic from Code Gallery.

Building and Running the Pausable Timer Job Sample

Test this project on your development or test site.

Building the Sample

  1. In Microsoft Visual Studio 2010, open the PausableAtCustomScope.sln file.

  2. Resolve the references to Microsoft.Office.Server.dll and Microsoft.SharePoint.dll in the %PROGRAMFILES%\Common Files\Microsoft Shared\web server extensions\14\ISAPI folder.

  3. Build the solution.

Running the Sample

To run the sample

  1. Register the built assembly in the global assembly cache (GAC) by running gacutil PausableAtCustomScopeTimerJob.dll.

  2. Run RegisterJob.ps1 from a Microsoft SharePoint Server 2010 command prompt, and pass in the URL of your Web application as the only argument.

  3. Navigate to Central Administration. Point to Monitoring, select Review job definitions, select Sample Pausable At Custom Scope Timer Job, and then click Run Now.

To pause a job while it is running

  • Run net pause sptimerv4 from a command prompt on the computer where the job is running. Or, to disable the job definition, navigate to Central Administration, point to Monitoring, select Review job definitions, select Sample Pausable At Custom Scope Timer Job, and then click Disable.

    There will be a delay of up to 15 seconds before you will see the state of the job change.

To resume a job while it is paused

  1. Run net continue sptimerv4 from a command prompt on the computer where the timer service is paused.

  2. Navigate to Central Administration. To enable the job definition, point to Monitoring, select Review job definitions, select Sample Pausable At Custom Scope Timer Job, and then click Enable.

    There will be a delay of up to 15 seconds before you will see the state of the job change.

See Also

Reference

SPPausableJobDefinition

Concepts

Enterprise Content Management (ECM) Development in SharePoint Server 2010

Deploying Content Between Servers in SharePoint Server 2010 (ECM)

Other Resources

Enterprise Content Management Resource Center

SharePoint Developer Center

SharePoint Developer Team Blog