Everybody, who at least once created a custom event receiver, knows property EventFiringEnabled(or DisableEventFiring method in SP2007). It allows to disable event firing, so SPListItem.Update() can be safely executed, without any other event receiver come in the way.

But what, when You want to disable event firing outside Your custom event receiver? There is a very simple way to do it.

The key to success is to create You own class that iherits from SPEventReceiverBase. After doing that, You will have access to the EventFiringEnabled property and You will be able to set its value.

What You need to remember, is that setting EventFiringEnabled property works only for the thread whom set it. If You would, for some reason, create new threads, You have to disable event firing for each thread separately.

Finally, the code that I use for disabling event firing:


public class SPEventReceiverManager : SPEventReceiverBase, IDisposable
{
#region Private Members

private bool _eventFiringEnabledOriginalValue;

#endregion

#region Public Properties

public bool EventsFiringEnabled
{
get
{
return this.EventFiringEnabled;
}
set
{
this.EventFiringEnabled = value;
}
}

#endregion

#region Constructors

public SPEventReceiverManager()
{
_eventFiringEnabledOriginalValue = this.EventFiringEnabled;
}

public SPEventReceiverManager(bool disableEventsFiring)
: this()
{
this.EventFiringEnabled = !disableEventsFiring;
}

#endregion

#region IDisposable Implementation

public void Dispose()
{
if (this.EventFiringEnabled != _eventFiringEnabledOriginalValue)
{
this.EventFiringEnabled = _eventFiringEnabledOriginalValue;
}
}

#endregion
}

Using it:


using(new SPEventReceiverManager(true))

{

// Some business logic.

item.Update();

}