Updating Items Safely in an Event Handler


This caused me lots of headaches a few months back, the SharePoint application pool was randomly crashing and the SharePoint logs were showing list item contention on updates. Eventually it all came back to the event handlers we had running within that site collection and an unpublished best practice for how to safely update list items from within item events.

Note that disabling event firing is only within the context of your event handler, not everything on that list/web/site etc. More information on this works can be found here: How DisableEventFiring / EventFiringEnabled works

2010
//update item with changes
this.EventFiringEnabled = false;
item.SystemUpdate();
this.EventFiringEnabled = true;

2007
this.DisableEventFiring();
item.SystemUpdate();
this.EnableEventFiring();

  1. No comments yet.
(will not be published)


%d bloggers like this: