开发者

BackgroundWorker Event Handlers

开发者 https://www.devze.com 2022-12-17 18:58 出处:网络
I have a BackgroundWorker object that I instantiated to perform a DB process on a background thread ansynchronously. I have event handlers for DoWork and RunWorkerComplete开发者_如何转开发d.

I have a BackgroundWorker object that I instantiated to perform a DB process on a background thread ansynchronously. I have event handlers for DoWork and RunWorkerComplete开发者_如何转开发d.

I can tell that the BackgroundWorker is disposing of itself because I added a MessageBox into the Disposed 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消