Re: Maintain list of attached event handlers (.Net 1.1)
- From: "Armin Zingler" <az.nospam@xxxxxxxxxx>
- Date: Wed, 11 Jul 2007 01:15:14 +0200
"Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx> schrieb
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.
Correct. In other words, the tree can live without the Form.
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
You're right, I could do this. Though, isn't it interesting that it is not possible to store the information I need to remember? I only want to remember "I attached this handler to that event". I am able to remember "this handler" because it's just a Delegate, but I am not able to rember "that event" (without using reflection).
I can not belive that it is not possible.
Armin
.
- Follow-Ups:
- Re: Maintain list of attached event handlers (.Net 1.1)
- From: Peter Duniho
- 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
- Re: Maintain list of attached event handlers (.Net 1.1)
- From: Peter Duniho
- Maintain list of attached event handlers (.Net 1.1)
- Prev by Date: Re: Maintain list of attached event handlers (.Net 1.1)
- Next by Date: Re: Thread safety of events
- 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
|