Is calling an extension method on a “null” reference (i.e. event with no subscribers) evil?

前端 未结 8 736
梦谈多话
梦谈多话 2020-12-12 16:05

Evil or not evil?

public static void Raise(this EventHandler handler, object sender, EventArgs args)
{
   if (handler != null)
   {
      handler(sender, arg         


        
8条回答
  •  情书的邮戳
    2020-12-12 16:33

    Don't forget to use [MethodImpl(MethodImplOptions.NoInlining)], else its possible that it isn't thread safe.

    (Read that somewhere long ago, remembered it, googled and found http://blog.quantumbitdesigns.com/tag/events/ )

提交回复
热议问题