When you troubleshoot or test your custom timer job, you will probably want to instantly run the job without waiting for the job to run in schedule.
If you have observed the Timer job definitions in SharePoint central administration, you will find that it gives you the capability to disable the job definition but it doesn’t allow you to execute it.
Figure 1. You cannot force the execution of the jobs through the Central Administration.
Note : For the out of the box timer jobs, you can use the stsadm –o execadmsvcjobs command but this will merely execute the administrative timer jobs but it will not execute the custom ones.
One way to work around this is changing the job schedule, deactivating and activating the feature that installs the timer jobs; this will do the trick by altering the Schedule Property of the job. You can use SharePoint Manager 2007 for monitoring the timer jobs status, schedule and the last run time. It’s very useful and time-saving rather than writing custom code to retrieve those values.
Figure 2. Using SharePoint Manager 2007 to monitor timer jobs.
So the only solution to force custom timer jobs to execute is using SharePoint object model as follows. Below is a code snippet that does the trick
Note : Forcing a timer job to execute out of schedule will neither alter the LastRunTime property of the job nor modify the schedule, so don’t let that fool you.
UPDATE : After I have posted this blog post, I received a notification from Robin Meuré, informing me of a tool that he has recently created and shared with the community on CodePlex, the tool is really nifty! It gives the administrators the ability to delete, disable and immediately run timer jobs from the browser without writing a single line of code. MARVELOUS!
I would like to extend a very special thank you to Robin for informing me of this tool. Go get the tool from codeplex and I’ll be waiting here 🙂