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.

Advertisements

~ by Matteo on March 15, 2007.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: