What is Event Recursion in SharePoint 2010? How to avoid it?

Event recursion or Event handler recursion is a problem which occurs in event receiver. Event recursion will update your item again and again. Event recursion is a reason for poor performance of SharePoint site.

How to Avoid Event Recursion

When working with event receivers, there is always a chance that your code will trigger the same event multiple time. As a result, the application pool will be recycled, which will be a poor performance by SharePoint Site.
To avoid this issue use EventFiringEnabled property which is exposed by the SPEventProperties base class and is available within event receivers.
You should set false and true before updating an item and after updating that item respectively.

Below is the code to avoid Event Recursion

 public override void ItemUpdating(SPItemEventProperties properties)
        {
            try
            {
                EventFiringEnabled = false;
                //Update item                
                properties.ListItem.Update();
                        
            }
            catch
            {
                          
            }
            finally
            {
                EventFiringEnabled = true; 
            }
        }

Leave a Comment

RSS
YouTube
YouTube
Instagram