Running Timed Jobs within SharePoint, Page 5
Remember to add a reference in the installation program to the "CountDocsJob" assembly. After compiling and executing the installation program, the Job is activated in the server. For test purposes, the installation uses a schedule time of one minute, but any time frame can be used, as explained earlier in the article.
If, after compilation, it is necessary to make modifications in the source code, delete the DLL from the GAC, copy the new version, execute an "iisreset" and, very important, stop and start the "Windows SharePoint Services Timer" from the Windows Services Manager (because the Job is cached by the service).
Figure 5: Output of Count Docs Job
Bear in mind that the Job expects to find a List in the main Web site of the portal, with the correct name ("MyJobs" in the example) and a "Description" field. An important point is that the error catching needs to be consistent: If an exception occurs, the Job will run continuously without issuing a warning. In the example, the error is logged in an external text file, but an entry in the Event Viewer might be a better solution.
Timed Jobs are an important component of SharePoint because they handle repetitive tasks without user involvement. Unfortunately, there are no facilities within SharePoint to install/de-install or activate Jobs; to achieve this, additional, custom-built software is necessary. On the positive side, programming Jobs does not differ from any standard SharePoint code used to realize common tasks with servers.
About the Author
Gustavo Velez is a MCSD Senior Application Developer for Winvision (http://www.winvision.nl), a Microsoft Gold Partner in the Netherlands. He has many years experience developing Windows and Office applications, and more than five years of daily programming with SharePoint. The author's articles, in English, Dutch, and Spanish, are found in many of the leading trade magazines and he's pleased to be Webmaster of http://www.gavd.net/servers, the only Spanish-language dedicated SharePoint site. Spanish-language readers may want to consult his book; Programacisn con SharePoint 2007.