Recently, I had to develop a timed job (an instant one-time job) on the SharePoint 2010.
During the development, I asked myself how I can debug the just created job, so I started searching for a solution.
First, the creation / instantiation of the timed job executes on behalf of the currently logged in user and is executed in the current web-request. So the debugging of this part of the code is quite simple:
Here a screenshot of the Add to process window to select multiple w3wp.exe processes:
This way, you can debug the creation of your timed job.
Now the main issue is, how you can debug the job-processing self. For this, you have to consider some points:
- The execution of your job is running in a different process (owstimer.exe)
- The job is called asynchronous, so you cannot define exactly when (at which second) the job is running
- If the service "SharePoint 2010 Timer" is not running on the machine, the job will never be executed
- Additionally (perhaps a bug): Sometimes, the breakpoints are not breaking, even if you attached the correct source to the correct process. In this case, you have to restart the "SharePoint 2010 Timer" service and everything works fine.
So to debug the job-processing, you have to follow these steps:
- Compile and deploy your code to the SharePoint 2010 server (as usual)
- Not always necessary, but I do it every time: Restart the "SharePoint 2010 Timer" service (more information about restarting services can be found at http://technet.microsoft.com/en-us/library/cc736564%28v=ws.10%29.aspx), thanks to Prasham
- Add a breakpoint to the
Execute(Guid) method in your
- Start the code
Here is a screenshot too about the attaching to a process, but this time, the owstimer.exe is selected:
This way, you can easily debug your
Most of the information about this article is from these two sites, thank you for this!:
I hope this helps anyone. Please feel free to write any comment or question!