Possible Duplicate:
Checking for null before event dispatching… thread safe?
Raise event thread safely – best practice
protected void NotificationEvent(Object sender, EventArgs e)
{
// Copy to a temporary variable to be thread-safe
EventHandler<EventArgs> tmp = mNotification;
if (tmp!= null)
{
tmp(this, null);
}
}
How does copying mNotification makes it thread-safe. Can someone explain?
If it were
mNotification could be set to null by another thread between
if (mNotification!=null)andmNotification(this, null);