Using IDisposable to unsubscribe events

前端 未结 9 2126
广开言路
广开言路 2020-11-28 05:52

I have a class that handles events from a WinForms control. Based on what the user is doing, I am deferencing one instance of the class and creating a new one to handle the

9条回答
  •  悲&欢浪女
    2020-11-28 06:46

    One option may be not to unsubscribe at all - just to change what the subscription means. If the event handler could be made smart enough to know what it's meant to do based on the context, you don't need to unsubscribe in the first place.

    That may or may not be a good idea in your particular case - I don't think we've really got enough information - but it's worth considering.

提交回复
热议问题