B
Bryan D.
Our application makes extensive use of C#'s event handling mechanism
to communicate between classes. A problem has cropped in that it
becomes difficult to know for sure that all observers of an object's
events have been deregistered when it's time to delete said object.
If some other object is registered for one of his events, he will not
get garbage collected and just lays around, receiving that event.
What I was hoping I could do would be to write a utility class that
could use Reflection on any object, walk over that object's events,
and then check to see if each event has a registered handler. This
does not appear to be doable through the means I've investigated
(Type.GetEvents(), EventInfo, EventDescriptor, etc.).
Does anyone have a good suggestion about how I could go about doing
this? Any strategies you've used to ensure event handlers are
deregistered when necessary?
Thank you all,
Bryan
to communicate between classes. A problem has cropped in that it
becomes difficult to know for sure that all observers of an object's
events have been deregistered when it's time to delete said object.
If some other object is registered for one of his events, he will not
get garbage collected and just lays around, receiving that event.
What I was hoping I could do would be to write a utility class that
could use Reflection on any object, walk over that object's events,
and then check to see if each event has a registered handler. This
does not appear to be doable through the means I've investigated
(Type.GetEvents(), EventInfo, EventDescriptor, etc.).
Does anyone have a good suggestion about how I could go about doing
this? Any strategies you've used to ensure event handlers are
deregistered when necessary?
Thank you all,
Bryan