I\'m a bit confused about C# Classes and their deconstructor.
I have to consume a few event handlers in a class instance I\'m getting in the constructor:
If you ever face the problem of having class A be a long lived class and class(es) B be short lived ones that subscribe to events of class A then you probably would be interested in the Weak Event Pattern. It can be a problem that you do not discover is one until it is to late i.e. Princeton self driving car.
Don't do it in the destructor, because it won't be called while the event handlers are attached : when you attach an instance method of Foo as a handler for an event of Bar, Bar will hold a reference to Foo, so Foo won't be garbage collected, and its destructor won't be called.
You should implement IDisposable, and dispose your object explicitly
public void Dispose()
{
if (handler != null)
{
handler.Load -= Load;
handler.Close -= Close;
}
}