【发布时间】:2010-09-21 04:07:26
【问题描述】:
以下代码来自 Josh Smith 的 MVVM 示例:
/// <summary>
/// Raised when this workspace should be removed from the UI.
/// </summary>
public event EventHandler RequestClose;
void OnRequestClose()
{
//if (RequestClose != null)
// RequestClose(this, EventArgs.Empty);
EventHandler handler = this.RequestClose;
if (handler != null)
handler(this, EventArgs.Empty);
}
注释行是我的补充。我的问题是注释行会与未注释行做同样的事情,对吗?那么为什么要创建另一个 EventHandler 引用呢?或者我在这里错过了什么?谢谢
【问题讨论】:
-
防止多个线程尝试注册或注销事件的问题
-
您能否详细说明或提供链接以供进一步阅读?我看不出创建对同一对象的另一个引用如何缓解这个问题。
-
这到底有什么帮助?你有什么参考或什么吗?除了分配引起的很小的延迟外,我没有看到任何对多线程有帮助的东西。
-
+1 感谢 Tanmoy 的链接,如果您发布答案,我也可以投票:)
标签: c# wpf mvvm event-handling