I can think of a few messy ways to solve this, but it strikes me that there should be a far more elegant solution than those which I've already come up with.
What's the most appropriate way for an object to cleanse itself of all of its event handlers prior to being disposed. It's a shame the event handler can't be enumerated upon.
In theory, is it considered more correct for the code adding the handler to an object to remember to remove it than assuming the object will clean itself up before it goes out of scope?
There is a way to avoid this common problem with events - WeakEvent pattern.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With