473,395 Members | 1,418 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Multicast Delegate bug?

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

Nov 17 '05 #1
0 899

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Edward Diener | last post by:
I am surprised that a MulticastDelegate does not have a particular member function which checks if a particular delegate is in its invocation list. I can do this manually of course but a Find, or...
0
by: IceShock | last post by:
I have been studying the C# language for sometime now and i have noticed something about delegates. When are single cast delegates to be used? even a better question: How do we define a singlecast...
6
by: Andrew Hayes | last post by:
Having to remember to unregister for events to prevent a ref count seems to be quite a burden to place on a developer. I have reviewed the WeakMulticastDelegate solution proposed by Xavier Musy...
1
by: Christoph Nahr | last post by:
The task: I want to let a background thread and a Windows Forms foreground thread communicate via callback methods. Now synchronization of a *single* delegate works just fine with the usual...
2
by: Nima | last post by:
The documentation for the Delegate and the MultiCastDelegate classes tell me that when we have a line like: public delegate void CheckAndPrintDelegate(string str); it causes the compiler to...
5
by: GVN | last post by:
Hi All, I recently worked on delegates. But I have a question regarding Multicast delegates. The scenario is as follows: I have a delegate myDelegate with object dlgt, and two methods...
2
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
What are the different features (in VB.NET) between a) Custom Events and b) Multicast Delegates to raise events? On the bottom line my class ad a) manages a list of handlers or ad b) obtains a...
5
by: AliRezaGoogle | last post by:
Hi, I have a conceptual question on Events and Multicast Delegates. Let me explain: As we know an event is a multicast delegate. What we declare as an event is inherently a multicast delegate....
9
by: raylopez99 | last post by:
Hello all— I’m trying to get the below to work and cannot get the format right. It’s from this example: http://msdn.microsoft.com/en-us/library/8627sbea(VS.71).aspx What it is: I’m trying...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.