【发布时间】:2011-10-11 12:05:45
【问题描述】:
可能重复:
Checking for null before event dispatching… thread safe?
Raise event thread safely - best practice
protected void NotificationEvent(Object sender, EventArgs e)
{
// Copy to a temporary variable to be thread-safe
EventHandler<EventArgs> tmp = mNotification;
if (tmp!= null)
{
tmp(this, null);
}
}
复制mNotification 如何使其成为线程安全的。谁能解释一下?
【问题讨论】:
-
一如既往,Eric Lippert 给出了答案:blogs.msdn.com/b/ericlippert/archive/2009/04/29/…
-
是的,没意识到
标签: c#