![]() | Coming Soon An innovative security and governance solution for SharePoint will soon be available here. Improve Compliance and Risk Management Protect Business-Critical Information and Processes. Please contact info at SharePoint2007Security.com for more information. |
SharePoint 2010 Event Receivers can be Synchronous or Asynchronous
I'm digging around the newly-released SharePoint 2010 SDK. I'll put up a post in the near future summarising the changes to security, but in the meantime here's one change I noted: after (-ed) event receivers can now be run synchronously!
This resolves a common complaint about SharePoint 2007 after-event receivers, which ran asychronously, often resulting in a race condition, invalid data, and confused users.
It's implemented in the code used to bind the event receiver, and not in the event receiver itself. Basically the SPEventReceiverDefinition class includes a Synchronization attribute, which can be set to SPEventReceiverSynchronization.Synchronous or SPEventReceiverSynchronization.Asynchronous (or, finally, SPEventReceiverSynchronization.Default);
SPEventReceiverDefinition eventReceiver = eventReceivers.Add();
eventReceiver.Synchronization = SPEventReceiverSynchronization.Synchronous;
....
Beffore event receivers are still always run synchronously,as they can be used to cancel the action. If you needed to, you could always spawn a new thread within your synchronous event receiver)


For more information on Sharepoint 2010 Event enhancements, check out the excellent article at : http://extreme-sharepoint.com/2011/12/27/event-receivers-sharepoint-2010/