Creating, Deploying, and Debugging Custom Timer Jobs in Windows SharePoint Services 3.0

Summary:  Learn how to harness the power of custom timer jobs in Windows SharePoint Services 3.0.

Applies to:  Windows SharePoint Services 3.0, Microsoft Office SharePoint Server 2007, Microsoft Visual Studio 2005

  Andrew Connell, Critical Path Training, LLC

March 2008

Windows SharePoint Services 3.0 lets you create custom jobs that are executed at set intervals. These jobs, known as timer jobs, are similar to those tasks that you can create in any version of Windows by using the Task Scheduler application. This capability is useful for scheduled process jobs because you keep everything in Windows SharePoint Services rather than create a console .exe file that is configured to run at set intervals by using the Windows Task Scheduler. The major benefits to using the Windows SharePoint Services timer service compared to using Windows Task Scheduler is that the timer service knows the topology of the Office SharePoint Server farm, and that you can load balance the jobs across all the servers in the farm or tie them to specific servers that are running particular services. This Microsoft Office Visual How To demonstrates how to create a job that requests the home page of each site collection in a Web application to force just-in-time (JIT) compilation and to speed up the first request.

Timer jobs are represented as Microsoft.SharePoint.Administration.SPJobDefinition objects. To create one, create a new class that inherits from SPJobDefinition. This new class minimally needs one constructor to create the job and a method that overrides the Execute method. This is the method that is called when the job is executed by Windows SharePoint Services.

Installing Custom Timer Jobs

After you create a timer job, the next step is to install it. Unfortunately, you cannot do this through the provided browser-based user interface; however, you can use the Windows SharePoint Services API. Developers can create custom applications, use PowerShell, or create custom STSADM commands to install the custom timer job. However, another technique is to use a Windows SharePoint Services 3.0 Feature to install and uninstall the custom timer job. Use a Feature receiver to install the feature as shown in the following example.

Creating custom timer jobs in Windows SharePoint Services 3.0 can be useful when a project requires a scheduled process to be executed. Timer jobs are the preferred way to create these scheduled tasks instead of creating a console application scheduled with Windows Task Scheduler.

One thing to remember when you are using site-scoped or site collection–scoped Features to install the timer jobs: The account that does the scheduling must have write permissions to the configuration database of the server farm. Usually, the identity of the application pool that is hosting the SharePoint site does not have permissions on the configuration database. This is the account that is used when you activate the Feature through the browser interface. However, if you activate the Feature by using STSADM, the identity of the interactive user is used. This enables someone with greater user rights to install the timer job.

Watch the Video

Length: 19:34 | Size: 19.5 MB | Type: WMV