473,326 Members | 2,114 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,326 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 2031
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...

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.