joek1975 joek1975 - 1 year ago 113 Question

BackgroundWorker Event Handlers

I have a

object that I instantiated to perform a DB process on a background thread ansynchronously. I have event handlers for
k and

I can tell that the
is disposing of itself because I added a
into the
event handler.

My question is this:

Is it necessary to detach the event handlers to ensure that the memory is cleaned up and that there are not memory leaks?

Answer Source

If an event publisher is being garbage collected, then there's no need to unsubscribe. You only need to unsubscribe from events if the event subscriber (the target of the handler delegate) needs to become eligible for garbage collection before the publisher does.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download