我有一个模型类,其中包含一个事件,我从其他类中订阅该事件。我想在每个类中正确地订阅和取消订阅。
- First I want to guarantee that in MyClass I unsibscribe only once even that code is in few methods.
Second there are other classes except MyClass witch use OnMyEvent so I don't want to unintentionally unsibscribe from the event in the class.
MyClass(IModel model) { _model = model; _model.OnMyEvent +=EventHandle; } Close() { _model.OnMyEvent -=EventHandle; } Disconnect() { //I want to check if OnMyEvent has already unsibscribed //Moreover OnMyEvent is used in other classes and //I don't want to mess up with it here _model.OnMyEvent -=EventHandle; }