How to stop event handler recursion

Hello Reader,

I have moved to new site and here is new article link from where you can post comments/feedback.

http://sanketinfo.blogspot.com/2009/12/how-to-stop-event-handler-recursion.html

Sorry for any inconvenience.

~Sanket

Advertisements

5 Responses

  1. The only way to disable event firing is using DisableEventFiring() and EnableEventFirigin()

    Nothing else, SystemUpdate() is used for different things.

    • Thank you Mukul for your comment, yeah I know SystemUpdate() is used for different things, In my sample code I have used update method for specific requirement but main point here is DisableEventFiring() and EnableEventFirigin() method.

  2. Well, and how to disable EventHandling outside Event Receiver? For example inside Workflow?

  3. Hi Mate,

    This worked for me when I needed to disableeventfiring from a webpart.

    Try creating a class like the below

    class HandleEventFiringInWebPart : SPItemEventReceiver
    {

    public void AccDisableEventFiring()
    {
    this.DisableEventFiring();
    }

    public void AccEnableEventFiring()
    {
    this.EnableEventFiring();
    }

    }

    then in the custom workflow action\ custom workflow\ webpart or wherever your executing the code from, create an instane of the object like so …

    HandleEventFiringInWebPart oEventRecieverHandler = new HandleEventFiringInWebPart();

    Then to disableeventfiring just exceute the method just before the code updates whatever list you need to like so ..

    //Need to disable event firing in the thread before attempting to update or add items

    oEventRecieverHandler.AccDisableEventFiring();

    ALWAYS REMEMBER to re-enable after you have finshed updating your list.

    I always do this by throwing it in the finally section like so …

    finally
    {

    //Make usre you reanble events firing in thread, after it has finished doing it’s stuff
    oEventRecieverHandler.AccEnableEventFiring();

    Kudos to whatever articles I ripped this off.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: