Quiz #1

Modify this apparently thread-safe event raiser in such a way it becomes truly thread-safe without changing signature nor implementation.

protected void OnMyEvent(MyEventArg e)
{
   MyEventHandler handler = MyEvent;

   if (handler != null)
      handler (this, e);
}

Inspired by this post by Pierre Greborio.

~ by Matteo on March 15, 2007.

Leave a Reply