Re: Maintain list of attached event handlers (.Net 1.1)



"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

.



Relevant Pages

  • Re: Store added event handlers
    ... list of sub objects, that can contain sub objects, and so on. ... I recursively process the object tree and attach ... event handlers to all the events of the objects in the tree. ... I detach the handler from the objects' events. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: about attachEvent() and detachEvent()
    ... hijack)", the previou fixes doesn't work any more. ... Is it possible to detach all attached event handler from an event, ... It is not event handlers that are attached, ... Determining a reference at runtime is ...
    (comp.lang.javascript)
  • Re: Detach Application.ThreadException Event, really?
    ... or even mentioned about the detach. ... I don't know any necessary special handling for static events. ... in the ApplicationExit or ThreadExit event handlers, ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Maintain list of attached event handlers (.Net 1.1)
    ... How can I remember which event handlers did I attach to which events? ... I recursively process the object tree and attach ... I must detach the remaining event handlers when closing the Form. ...
    (microsoft.public.dotnet.framework)
  • Re: Maintain list of attached event handlers (.Net 1.1)
    ... How can I remember which event handlers did I attach to which events? ... I recursively process the object tree and attach ... I detach the event handler. ...
    (microsoft.public.dotnet.framework)