When you are going to raise an event, you should first check to see if there are any subscribers to the event. If there are none then you shouldn't raise the event. The event value should be put into a local variable, checked for null (this determines if there are any subscribers) and then raised if there are subscribers. The code should look something like this:

var eventHandler = this.Event;
if (eventHandler != null)
{
    eventHandler(this, eventArgs);
}

Last edited Dec 26, 2010 at 10:02 PM by JeffLeBert, version 1

Comments

No comments yet.