Wednesday, June 6, 2012

Debugging Custom SharePoint 2010 Timer Jobs

For those of you who have seen posts on how to debug custom timer jobs, you have probably noticed that many of the solutions do not work, or only work part of the time. The foolproof, 100% method for getting an instance of the debugger running on your timer job is to add this line of code at the top of your Execute method:

System.Diagnostics.Debugger.Launch();

This will immediately pause the job and prompt you to launch a debug instance, which can be done in your open VS project. Once the debug instance is running, you can resume running the job.