Re: How to Remove an Event Handler without knowing the name of the handler

From: Charles Law (blank_at_nowhere.com)
Date: 06/10/04


Date: Thu, 10 Jun 2004 15:41:35 +0100

Herfried

On the same note, how about the reverse process? That is, given

Public Class ClassA

Public Event MyEvent()
...
AddHandler MyEvent, AddressOf ClassBInstance.MyEventHandler
...
End Class

When ClassBInstance is destroyed, how can all events that MyEventHandler
handles be disconnected without ClassB knowing what events have been linked?
Is there another hidden variable?

Charles

"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:2ir5sjFqdgtsU1@uni-berlin.de...
> * "Charles Law" <blank@nowhere.com> scripsit:
> > Is there a way to dynamically remove an event handler from an event
without
> > knowing the name of the handler?
> >
> > For example, how can ClassB remove the handler without knowing the name,
or [...]
> > Public Class ClassB
> >
> > Public Event DoStuff()
> >
> > Public Sub AddHandler(handler As EventHandler)
> >
> > AddHandler DoStuff, AddressOf handler
> >
> > End Sub
> >
> > Public Sub RemoveHandlers()
> >
> > ' *** Remove unknown handler(s) ***
> > RemoveHandler DoStuff, ???
> >
> > End Sub
> >
> > End Class
> > </code>
> >
> > Presumably, the list of currently connected event handlers is held
> > somewhere. Can it be accessed in some way to remove an indeterminate
number
> > of handlers?
>
> In 'ClassB', have a look at 'DoStuffEvent'. This is a hidden variable.
>
> --
> Herfried K. Wagner [MVP]
> <URL:http://dotnet.mvps.org/>



Relevant Pages


Loading