Which C# pattern has better performance to avoid duplicated event handlers?

前端 未结 4 787
你的背包
你的背包 2021-02-14 03:54

There are basically two patterns in avoiding duplicated registering of event handlers: (According to this discussion: C# pattern to prevent an event handler hooked twice)

<
4条回答
  •  走了就别回头了
    2021-02-14 04:36

    MyEvent -= MyEventHandlerMethodfirst need to find the registered event handler in the invocation list in order to remove it. So GetInvocationList().Contains is better, but it's truely insignificant.

    But, notice that you can't access event EventHandler foo's invocation list....

提交回复
热议问题