473,396 Members | 2,013 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,396 software developers and data experts.

Multicast delegate checking for particular delegate

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 something like that, should
have been a member function of the MulticastDelegate.
Jul 21 '05 #1
3 2037
Edward Diener <ed******@tropicsoft.com> wrote:
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 something like that, should
have been a member function of the MulticastDelegate.


I don't think it's the kind of thing that's used very often, to be
honest. I certainly have never needed it myself, and I can't remember
anyone ever asking for it before...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Jon Skeet [C# MVP] wrote:
Edward Diener <ed******@tropicsoft.com> wrote:
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
something like that, should have been a member function of the
MulticastDelegate.


I don't think it's the kind of thing that's used very often, to be
honest. I certainly have never needed it myself, and I can't remember
anyone ever asking for it before...


It could be used to make sure that a delegate referencing the same member
function is not added twice or removed if it is not already there. The
former is more important as I assume attempting to remove a delegate which
does not already exist does nothing. However adding the same member function
twice is probably not wise.

It might be argued that any code which could add the same handler twice is
flawed in it design, and that may be so. When you replied I re-checked my
code that I was writing to prevent that and realized that if my logic was
correct, it could not happen by design. However I can imagine situations
where a Find might be useful, or a MulticastDelegate function which only
adds a delegate handler if that delegate handler does not already exist in
its invocation list might be useful.
Jul 21 '05 #3
Edward Diener <ed******@tropicsoft.com> wrote:
I don't think it's the kind of thing that's used very often, to be
honest. I certainly have never needed it myself, and I can't remember
anyone ever asking for it before...
It could be used to make sure that a delegate referencing the same member
function is not added twice or removed if it is not already there. The
former is more important as I assume attempting to remove a delegate which
does not already exist does nothing. However adding the same member function
twice is probably not wise.


Well, in some cases it's not. In some cases it's exactly what you want.
It might be argued that any code which could add the same handler twice is
flawed in it design, and that may be so. When you replied I re-checked my
code that I was writing to prevent that and realized that if my logic was
correct, it could not happen by design. However I can imagine situations
where a Find might be useful, or a MulticastDelegate function which only
adds a delegate handler if that delegate handler does not already exist in
its invocation list might be useful.


The easiest way of doing that is probably just to remove it first, to
be honest.

myDelegate -= foo;
myDelegate += foo;

Admittedly that won't reduce the number if it's been added more than
once already...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4

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

Similar topics

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...
0
by: Rick Strahl [MVP] | last post by:
Hi all, I have the following code: if (DocEvents.oncontextmenu != null) DocEvents.oncontextmenu += new HTMLDocumentEvents2_oncontextmenuEventHandler(this.RaiseContextMenuClicked); This...
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...
1
by: Hiten | last post by:
Hi I have created multicast delegates, now i want to point to perticular reference from delegate to invoke that mathod how do i do that please any one know it..... Thanks --- Hitendra
0
by: Andrew Ducker | last post by:
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...
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...
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...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.