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



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
.



Relevant Pages

  • Re: Maintain list of attached event handlers (.Net 1.1)
    ... > The Form is an observer of some objects working in the background ... > straighter to detach the event handlers when closing the Form. ... The tree is only in some data structure, ... should unsubscribe itself from any events to which it's subscribed. ...
    (microsoft.public.dotnet.framework)
  • Re: Crypto test removal request from Theo de Raadt
    ... It has now been deleted from the NetBSD tree as well. ... > Please delete it from the FreeBSD tree as well. ... > Content-Type: text/plain; ... > To unsubscribe, ...
    (freebsd-current)
  • RE: [openib-general] [RFC] Move InfiniBand .h files
    ... > tree that might want to use IB support. ... > kernel tree, since one would have to link both drivers/infiniband ... > problem goes away if/when OpenIB shifts over to a new source code ... To unsubscribe from this list: send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: HELP! cant become root
    ... directory tree. ... They don't walk up the tree ... it would be way too dangerous to have any utility work that way. ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)
  • Re: Maintain list of attached event handlers (.Net 1.1)
    ... memory is done when it is required/when it is convenient. ... As you can see, the question of whether or not to unsubscribe the event handlers as soon as they can be continues to distract Armin from the real issue: how to clean up when the form is closed. ... The real question here IMHO is whether to make any attempt to track which event handlers have been unsubscribed. ...
    (microsoft.public.dotnet.framework)