【发布时间】:2017-10-04 12:19:21
【问题描述】:
可用于调用委托或事件的 ?. 运算符是否避免了竞争条件?
例如。手动避免竞争条件:
//The event-invoking method that derived classes can override.
protected virtual void OnShapeChanged(ShapeEventArgs e)
{
// 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<ShapeEventArgs> handler = ShapeChanged;
if (handler != null)
{
handler(this, e);
}
}
来源:msdn
【问题讨论】:
标签: c# events delegates race-condition