| Author: Allen B. Taylor 07 Aug 2007 | Member Level: Bronze Points : 0 |
I agree that the lock is necessary to ensure that multiple adders and removers don't clobber each other, but since delegates are immutable objects, I don't see how the lock is necessary in the OnTestEvent method in the example. The delegate (testDelegate in this case) will never be in an indeterminate state; it simply gets replaced with a new immutable delegate after an add or remove, so it can be read without the need for locking.
Also, the example code fails to handle the case where one of the clients throws an exception. Such a case causes all other clients in the list to miss the event. This issue is dealt with in many other places, so I won't elaborate here.
|
| Author: Anthony 28 May 2008 | Member Level: Bronze Points : 2 |
I just read this exact example at another web page. It is a very good, comprehensive article about delegates and events.
http://www.yoda.arachsys.com/csharp/events.html
|
| Author: Mahesh Raj 07 Jun 2008 | Member Level: Gold Points : 1 |
This is very good information,Continue posting such useful articles.
|