Re: Maintain list of attached event handlers (.Net 1.1)
- From: "Armin Zingler" <az.nospam@xxxxxxxxxx>
- Date: Tue, 10 Jul 2007 23:48:20 +0200
"Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx> schrieb
On Tue, 10 Jul 2007 13:40:17 -0700, Armin Zingler
<az.nospam@xxxxxxxxxx> wrote:
> [...]
> - In a Form's Load event, I recursively process the object tree
> and attach
> event handlers to all the events of the objects in the tree.
>
> - Whenever an event fires, I detach the event handler. (because it
> won't fire twice)
>
> - When the Form closes, maybe not all events have been fired.
> Therefore, there are still event handlers attached to these
> events.
>
> My goal is:
> I must detach the remaining event handlers when closing the Form.
I don't see any need to detach the event handler regardless. It is
not really hurting anything for it to remain attached even after the
event fires, other than a very minimal amount of memory occupied. And if you are releasing the object itself, any attached event
handlers will also be released at that time, without you doing
anything extra.
Why is it that you think you need to detach the event handlers?
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.
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
- Maintain list of attached event handlers (.Net 1.1)
- Prev by Date: Re: DataTable.Select with condition with Timespan values
- Next by Date: 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
|