Re: Maintain list of attached event handlers (.Net 1.1)
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Tue, 10 Jul 2007 15:36:52 -0700
On Tue, 10 Jul 2007 14:48:20 -0700, Armin Zingler <az.nospam@xxxxxxxxxx> wrote:
The Form is an observer of some objects working in the background in another thread. After the Form has closed, it doesn't have to observe the events anymore. In the event handlers, I call Me.BeginInvoke to marshal the work to the UI thread, but as there is no Form, there is no need to do this anymore. Of course, I could always query "IsHandleCreated" in each event handler, but I think it's straighter to detach the event handlers when closing the Form.
Ah, I misunderstood. Sorry. Your original wording made it sound as though it was the objects owned by the form itself that exposed the event. Just to clarify: the form itself does not actually contain the tree. The tree is only in some data structure, and form subscribes to an event (or events) on each and every object within the tree. And yes, I agree that if the form is going away, it should unsubscribe itself from any events to which it's subscribed.
It is not a problem to unsubscribe from an event that you are not subscribed to. So one option is to simply go through an unsubscribe from every event when the form unloads, just as you go through and subscribe to every event when the form loads.
I do not believe there is any point in unsubscribing when the event fires, even if the event will never be raised again. So, if you agree with that then you can simply do as I suggest above (unsubscribe to every event when the form unloads) _without_ bothering to unsubscribe any other time.
Pete
.
- Follow-Ups:
- Re: Maintain list of attached event handlers (.Net 1.1)
- From: Armin Zingler
- Re: Maintain list of attached event handlers (.Net 1.1)
- References:
- Maintain list of attached event handlers (.Net 1.1)
- From: Armin Zingler
- Re: Maintain list of attached event handlers (.Net 1.1)
- From: Peter Duniho
- Re: Maintain list of attached event handlers (.Net 1.1)
- From: Armin Zingler
- Maintain list of attached event handlers (.Net 1.1)
- Prev by Date: Thread safety of events
- Next by Date: Re: Maintain list of attached event handlers (.Net 1.1)
- Previous by thread: Re: Maintain list of attached event handlers (.Net 1.1)
- Next by thread: Re: Maintain list of attached event handlers (.Net 1.1)
- Index(es):
Relevant Pages
|