In the list of Visual C# 2010 Breaking Changes there is an entry on “Event synchronization” which states that you must now create a local copy of a delegate to check for null (before calling it) in order to avoid a race condition. Wasn’t this already the “best practice” pattern anyhow?
Does this change make any difference in the StackOverflow discussion on C# Events and Thread Safety?
Well, you didn’t have to take a copy if you used exactly the code they’d got there – because it was locking on
this. However:thisis a bad idea to start withSo code which was already bad practice is now actively broken. Ho hum. The normal implementation of events (which doesn’t hold a lock but does copy the variable) isn’t changed by this.
See the Chris Burrows blog post about event best practices for more information.