When you disable event firing, it should not be kept disabled

This post is a contribution from Nishand Vasudevan, an escalation engineer with the SharePoint Developer Support team.

Disabling the event receivers can stop the workflow events.  For example, disabling the event can stop workflow from starting and could stops firing events like OnTaskChanged.

The below code will not trigger OnTaskChanged event that otherwise would.  The code snippet is to depict what you shouldn’t be doing in your code and it’s an illustrative example.

    1: public class EventFiringHandler : SPItemEventReceiver
    2: {
    3:    public void DisableHandleEventFiring()
    4:    {
    5:       this.EventFiringEnabled = false;
    6:    }
    7:    
    8:    public void EnableHandleEventFiring()
    9:    {          
   10:       this.EventFiringEnabled = true;
   11:    }
   12: }
    1: EventFiringHandler handler = new EventFiringHandler();
    2: SPSite mysite = new SPSite("https://localhost/");
    3: SPWeb web = mysite.OpenWeb();
    4: SPList list = web.Lists["Tasks"];
    5: SPListItem item = list.GetItemById(<taskItemID>);
    6: Hashtable hashT = new Hashtable();
    7: hashT.Add("Title","MyNewTitle");
    8: handler.DisableHandleEventFiring();
    9: SPWorkflowTask.AlterTask(item, hashT, true);

Hope this helps!