Puzzling one for the really geeky people here...
I have a multicast delegate responding to an event, and I want to
remove some of the delegate from it, but it doesn't work as I'd expect.
The following code works as you'd expect:
BlankDelegate x = new BlankDelegate(Respond1);
x += new BlankDelegate(Respond2);
x += new BlankDelegate(Respond3);
Event1 += x;
BlankDelegate y = new BlankDelegate(Respond2);
y += new BlankDelegate(Respond3);
Event1 -= x;
i.e. Respond1,2 and 3 are added, then 2 and 3 are removed, so that when
Event1 fires, only Respond1 is triggered.
However, if I add 1,2 and 3, then remove 1 and 3, like so:
BlankDelegate x = new BlankDelegate(Respond1);
x += new BlankDelegate(Respond2);
x += new BlankDelegate(Respond3);
Event1 += x;
BlankDelegate y = new BlankDelegate(Respond1);
y += new BlankDelegate(Respond2);
Event1 -= y;
then _none_ of them are removed and firing event1 causes _all_ of them
to fire.
I _think_ that what's happening is that when it's comparing y to Event1
it's not finding a match, because the 'Previous' link is being compared
along with the rest of the object.
Anyone else seen this happen, or offer an explanation?
Cheers,
Andy D