我只是在MSDN 上阅读有关事件的页面,我遇到了一段令我困惑的示例代码.
有问题的代码是这样的:
// Make a temporary copy of the event to avoid possibility of
// a race condition if the last subscriber unsubscribes
// immediately after the null check and before the event is raised.
EventHandler<CustomEventArgs> handler = RaiseCustomEvent;
Run Code Online (Sandbox Code Playgroud)
我理解代码的意图,但我没有看到该特定行如何制作任何东西的副本.它所做的只是复制参考 ; 它实际上并没有制作委托实例的深层副本.所以为此,它实际上并没有完全阻止竞争条件.
我错过了一些明显的东西吗?