473,378 Members | 1,507 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,378 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 2033
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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...

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.