Thursday, 7 February 2013

Debugging Event Receivers in SharePoint 2010


By default event receivers are asynchronous meaning that they run under the SharePoint timer service (OWSTIMER.exe). This means that the event receivers:
  1. Are not executed immediately, rather it is scheduled to be executed by OWSTIMER.exe.
  2. Don’t run under w3wp.exe process anymore, so when you want to debug your event receivers, you have to attach to OWSTIMER.EXE and wait till they are executed.
However, you can control this behavior using the Synchronization attribute:


If you set it to Synchronous, then the event receivers run immediately and under the w3wp.exe process. So, if your solution depends on event receivers highly and expect the results immediately, then you have to set it to Synchronous, else setting it to Asynchronous should do the job.
______________________________________________________________________________

Also, if you’re looking for a easy to debug an event receiver without having to manually attach a debugger to your code, you can use the System.Diagnostics.Debugger.Launch() method. 


1
System.Diagnostics.Debugger.Launch();



Add it anywhere you want  in your code, deploy your solution and begin testing. Before you can begin debugging, a popup window will appear providing you options where to debug your code, choose an option and begin to debug your code.

2 comments:

  1. Some truly superb blog posts on this web site ,thank you for contribution.
    sharepoint administrator training

    ReplyDelete
  2. In SharePoint 2013 event receiver runs in only in w3wp.exe, it does not matter that the event is Synchronous or Asynchronous

    ReplyDelete