Avoid duplicate event subscriptions in C#

前端 未结 5 1981
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-25 15:28

How would you suggest the best way of avoiding duplicate event subscriptions? if this line of code executes in two places, the event will get ran twice. I\'m trying to avoid

5条回答
  •  旧时难觅i
    2020-12-25 15:48

    Is your code multi threaded ? Concurrency lock is needed only when its multi threaded. If not its a overhead.

    As such your approach of unsubscribing and subscribing is correct.

    Thanks

提交回复
热议问题