C# event handlers not thread safe?

Posted by Daniel on Stack Overflow See other posts from Stack Overflow or by Daniel
Published on 2010-04-06T01:01:57Z Indexed on 2010/04/06 1:03 UTC
Read the original article Hit count: 287

Filed under:
|
|
|

So i've read around that instead of calling a event directly with

if (SomeEvent != null)
   SomeEvent(this, null);

i should be doing

SomeEventHandler temp = SomeEvent;
if (temp != null)
    temp(this, null);

Why is this so? How does the second version become thread safe? What is the best practice?

© Stack Overflow or respective owner

Related posts about c#

Related posts about events