是否?.
可用于调用委托或事件的运算符避免竞争条件?
例如。手动避免竞争条件:
//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);
}
}
source: msdn https://learn.microsoft.com/en-us/dotnet/articles/csharp/programming-guide/events/how-to-raise-base-class-events-in-derived-classes
Yes
空条件成员访问的另一个用途是调用委托
以线程安全的方式使用更少的代码。
...
新方法是线程安全的,因为编译器生成代码
仅评估一次 PropertyChanged
MSDN 来源 https://learn.microsoft.com/en-us/dotnet/articles/csharp/language-reference/operators/null-conditional-operators
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)