Re: unhooking events by Thomas
Thomas
Wed Nov 19 09:27:19 CST 2003
You should be able to do this:
event EventHandler myEvent;
adding:
myEvent += new EventHandler(mymethod);
removing:
myEvent -= new EventHandler(mymethod);
I guess the theory is that the underlying delegate list is using the Equals
method on the delegate object, which must be comparing the values of the
delegate object instead of object identity. Thus you are not required to the
original EventHandler object that you added.
Hope this helps
Thomas
"John" <anonymous@discussions.microsoft.com> wrote in message
news:034e01c3ae8f$c292e8f0$a001280a@phx.gbl...
> Hi,
>
> Does anyone know a way that I can unhook an event without
> passing the original event handler ?
>
> i.e I want to do like this:
>
> foreach(eventhandler in object.SomethingChanged)
> {
> object.SomethingChanged -= SomethingChanged(abc);
> }
>
> John