finding out the count of "subscibers" on an event

  • Thread starter Thread starter Ron M. Newman
  • Start date Start date
R

Ron M. Newman

Hi,

My class has an event to which other classes subscribe (e.g. myevent+=
foreignDelagate). I'd like to find out how many subscribers "myEvent" has.
Up till now I tested it for "null" or '!null" to find out if it has anything
there, but I need an exact number of subscribers. Is there any way to query
it?

Thanks!
-Ron
 
Ron,

All events are delegate chains. If the instance of the delegate is not
null, you can call the GetInvocationChain method on the delegate to get the
invocation chain for it. It returns an array of delegates that constitute
the chain.

Then, you can just return the length of the array.

Hope this helps.
 
Yes, that's what I was looking for. Thanks!
-Ron

Nicholas Paldino said:
Ron,

All events are delegate chains. If the instance of the delegate is not
null, you can call the GetInvocationChain method on the delegate to get
the invocation chain for it. It returns an array of delegates that
constitute the chain.

Then, you can just return the length of the array.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ron M. Newman said:
Hi,

My class has an event to which other classes subscribe (e.g. myevent+=
foreignDelagate). I'd like to find out how many subscribers "myEvent"
has. Up till now I tested it for "null" or '!null" to find out if it has
anything there, but I need an exact number of subscribers. Is there any
way to query it?

Thanks!
-Ron
 
Back
Top