This project is read-only.

EventHandlerHelper event raising is error-prone


The code for raising an event is not that recommended in Framework Design Guidelines by Cwalina and Abrams; it does not make a local copy and check for null before invoking. See for the following example:
class Counter
    public event EventHandler ThresholdReached;

    protected virtual void OnThresholdReached(EventArgs e)
        EventHandler handler = ThresholdReached;
        if (handler != null)
            handler(this, e);

    // provide remaining implementation for the class


pckujawa wrote Jul 31, 2013 at 7:03 PM

I may have forgotten that passing the event handler as a parameter makes a local copy, so the copy step within the method is redundant (see comments at So maybe the code is equivalent. Sorry about that.