可用于调用委托或事件的?.
运算符是否可以避免竞争条件?
EG。手动避免竞争条件:
//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
答案 0 :(得分:2)
是强>
null条件成员访问的另一个用途是调用委托 以线程安全的方式使用更少的代码。
...
新方法是线程安全的,因为编译器会生成代码 仅评估一次PropertyChanged