C# coding std v1.81 / 38.a

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I'm reading the C# coding standard and I don't understand the following item (38)

38. With delegates as class members
a) Copy a delegate to a local variable before publishing to avoid concurrency race condition

What is the reasoning here

Thanks
Tom
 
TT (Tom Tempelaere) <"=?Utf-8?B?VFQgKFRvbSBUZW1wZWxhZXJlKQ==?=" <_N_
0SPA|/\|[email protected]|/\|APS0_N_> said:
I'm reading the C# coding standard and I don't understand the following item (38):

38. With delegates as class members:
a) Copy a delegate to a local variable before publishing to avoid
concurrency race condition.

What is the reasoning here?

You normally need to do a test for the delegate being null before
invoking it. If you don't copy it to a local variable first, you could
end up testing it for null, then trying to invoke it, with something
else setting it to null between the test and the invocation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top