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

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



Re: unhooking events by John

John
Wed Nov 19 10:40:53 CST 2003

Will this work if I have alot of objects hooked to the
same event?

PS. I am doing this in a different class to where the
delegate is


>-----Original Message-----
>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
>
>
>.
>