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

What keeps track of delegates?

jm
If I have multiple subscribers to a delegate, what keeps track of them?
Are they out there on the heap?

When I declare a delegate:

public delegate void MyDelegate (object myObject, MyObjectEventArgs
myEvent);
public MyDelegate SomethingHappened;

and later I have two subscribers, what's going on in the background.
My Delegate "variable," if that is what it's called just looks like a
variable, but behind the scenes it can hold multiple instances of
subscribers, correct, like an array? Just wondered what was going on.
I'm "protected" from it by the .Net framework.

Thanks.

Nov 17 '06 #1
5 1344
jm <ne***********@gmail.comwrote:
If I have multiple subscribers to a delegate, what keeps track of them?
Are they out there on the heap?

When I declare a delegate:

public delegate void MyDelegate (object myObject, MyObjectEventArgs
myEvent);
public MyDelegate SomethingHappened;

and later I have two subscribers, what's going on in the background.
My Delegate "variable," if that is what it's called just looks like a
variable, but behind the scenes it can hold multiple instances of
subscribers, correct, like an array? Just wondered what was going on.
I'm "protected" from it by the .Net framework.
I don't know the answer difinitively, but since it appears to be a classic
observer pattern, it is like a collection of delegate (class) instances on the
object being observed. Thus, if you listen to the events on a form, the
delegate instances are part of the form instance. THat is why it is good
practice to unregister your events when you are no longer interested in
listening for them.

Perhaps somebody else will answer more definitively.

--
Thomas T. Veldhouse
Key Fingerprint: D281 77A5 63EE 82C5 5E68 00E4 7868 0ADC 4EFB 39F0
Nov 17 '06 #2
The System.Delegate class from which your delegate inherits maintains an
invocation list for a delegate -- a list of methods that will be called when
the delegate is invoked.

When you invoke the delegate, the base class implementation loops through
the list and calls each method.

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"jm" wrote:
If I have multiple subscribers to a delegate, what keeps track of them?
Are they out there on the heap?

When I declare a delegate:

public delegate void MyDelegate (object myObject, MyObjectEventArgs
myEvent);
public MyDelegate SomethingHappened;

and later I have two subscribers, what's going on in the background.
My Delegate "variable," if that is what it's called just looks like a
variable, but behind the scenes it can hold multiple instances of
subscribers, correct, like an array? Just wondered what was going on.
I'm "protected" from it by the .Net framework.

Thanks.

Nov 17 '06 #3
Hi Peter,

More accurately, it's the MulticastDelegate class, which derives from
Delegate, that provides the invocation list.

--
Dave Sexton

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comwrote in message
news:6F**********************************@microsof t.com...
The System.Delegate class from which your delegate inherits maintains an
invocation list for a delegate -- a list of methods that will be called when
the delegate is invoked.

When you invoke the delegate, the base class implementation loops through
the list and calls each method.

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"jm" wrote:
>If I have multiple subscribers to a delegate, what keeps track of them?
Are they out there on the heap?

When I declare a delegate:

public delegate void MyDelegate (object myObject, MyObjectEventArgs
myEvent);
public MyDelegate SomethingHappened;

and later I have two subscribers, what's going on in the background.
My Delegate "variable," if that is what it's called just looks like a
variable, but behind the scenes it can hold multiple instances of
subscribers, correct, like an array? Just wondered what was going on.
I'm "protected" from it by the .Net framework.

Thanks.


Nov 17 '06 #4
And by default, they are executed syncronous and in list order. You can
invoke them yourself on a seperate threads if that is something you need.

--
William Stacey [C# MVP]

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:em**************@TK2MSFTNGP03.phx.gbl...
| Hi Peter,
|
| More accurately, it's the MulticastDelegate class, which derives from
| Delegate, that provides the invocation list.
|
| --
| Dave Sexton
|
| "Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comwrote in message
| news:6F**********************************@microsof t.com...
| The System.Delegate class from which your delegate inherits maintains an
| invocation list for a delegate -- a list of methods that will be called
when
| the delegate is invoked.
| >
| When you invoke the delegate, the base class implementation loops
through
| the list and calls each method.
| >
| Peter
| >
| --
| Co-founder, Eggheadcafe.com developer portal:
| http://www.eggheadcafe.com
| UnBlog:
| http://petesbloggerama.blogspot.com
| >
| >
| >
| >
| "jm" wrote:
| >
| >If I have multiple subscribers to a delegate, what keeps track of them?
| > Are they out there on the heap?
| >>
| >When I declare a delegate:
| >>
| >public delegate void MyDelegate (object myObject, MyObjectEventArgs
| >myEvent);
| >public MyDelegate SomethingHappened;
| >>
| >and later I have two subscribers, what's going on in the background.
| >My Delegate "variable," if that is what it's called just looks like a
| >variable, but behind the scenes it can hold multiple instances of
| >subscribers, correct, like an array? Just wondered what was going on.
| >I'm "protected" from it by the .Net framework.
| >>
| >Thanks.
| >>
| >>
|
|
Nov 18 '06 #5
In the delegates samples section of the .Net 1.1 framework SDK there's a chat
sample that manually calls methods from the invocation list. It's a great
tutorial on this topic.

On my PC, the sample is at C:\Program Files\Microsoft Visual Studio .NET
2003\SDK\v1.1\Samples\Technologies\DelegatesAndEve nts\cs

I point that out because there are other chat samples in the SDK that do not
use the same technology.

Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA
"William Stacey [C# MVP]" wrote:
And by default, they are executed syncronous and in list order. You can
invoke them yourself on a seperate threads if that is something you need.

--
William Stacey [C# MVP]

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:em**************@TK2MSFTNGP03.phx.gbl...
| Hi Peter,
|
| More accurately, it's the MulticastDelegate class, which derives from
| Delegate, that provides the invocation list.
|
| --
| Dave Sexton
|
| "Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comwrote in message
| news:6F**********************************@microsof t.com...
| The System.Delegate class from which your delegate inherits maintains an
| invocation list for a delegate -- a list of methods that will be called
when
| the delegate is invoked.
| >
| When you invoke the delegate, the base class implementation loops
through
| the list and calls each method.
| >
| Peter
| >
| --
| Co-founder, Eggheadcafe.com developer portal:
| http://www.eggheadcafe.com
| UnBlog:
| http://petesbloggerama.blogspot.com
| >
| >
| >
| >
| "jm" wrote:
| >
| >If I have multiple subscribers to a delegate, what keeps track of them?
| > Are they out there on the heap?
| >>
| >When I declare a delegate:
| >>
| >public delegate void MyDelegate (object myObject, MyObjectEventArgs
| >myEvent);
| >public MyDelegate SomethingHappened;
| >>
| >and later I have two subscribers, what's going on in the background.
| >My Delegate "variable," if that is what it's called just looks like a
| >variable, but behind the scenes it can hold multiple instances of
| >subscribers, correct, like an array? Just wondered what was going on.
| >I'm "protected" from it by the .Net framework.
| >>
| >Thanks.
| >>
| >>
|
|
Nov 19 '06 #6

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

Similar topics

2
by: Sandman | last post by:
Just looking for suggestion on how to do this in my Web application. The goal is to keep track of what a user has and hasn't read and present him or her with new material I am currently doing...
9
by: Gummy | last post by:
Hello, I created a user control that has a ListBox and a RadioButtonList (and other stuff). The idea is that I put the user control on the ASPX page multiple times and each user control will...
2
by: BurtonBach | last post by:
I have a small database that mostly keeps track of material quantities going into jobs we do. I have been able to make this work well for me. I now want to add the tracking of a rolling balance of...
1
by: =?Utf-8?B?V2luRGV2?= | last post by:
I have a machine that I've moved some web services to and now w3wp.exe just keeps taking more and more memory (I don't think it did it on the old machine.) So apparently I have a memory leak...
6
by: =?Utf-8?B?T2xkQ2FEb2c=?= | last post by:
My question is regarding the use of delegates in C#. I see how .Net uses delegates to wire event handlers to events. It’s an object created by a single line of code by the system and that makes...
89
by: Tubular Technician | last post by:
Hello, World! Reading this group for some time I came to the conclusion that people here are split into several fractions regarding size_t, including, but not limited to, * size_t is the...
1
by: phpmel | last post by:
Hi guys, I wanted a text box that keeps track of the current time in the format 09:23AM etc I know I have to use time() function but that would only give you the current time when the page was...
69
by: raylopez99 | last post by:
They usually don't teach you in most textbooks I've seen that delegates can be used to call class methods from classes that are 'unaware' of the delegate, so long as the class has the same...
8
by: jehugaleahsa | last post by:
Hello: We wrote an entire application where we add our DataRows to our DataTables immediately. However, we have to shut off our constraints to do this. We would like to use detached DataRows to...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.