I'm trying to find a way to determine the number of subscribers there are to a timer's elapsed event. From my searches, it seems like I should use GetInvocationList(). However when I try:
Private _schedulingTimer As Timers.Timer
Private Sub SomeMethod()
dim test = _schedulingTimer.Elapsed.GetInvocationList()
End Sub
I get the following error:
'Public Event Elapsed As ElapsedEventHandler' is an event and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
Am I doing something wrong? Is there another way to get what I am after?
You can call GetInvocationList
on a delegate, but an event isn't a delegate - an event is just a consistent way of exposing "subscribe" and "unsubscribe" operations, and a simple way of implementing those operations (using delegates).
Accessing the registered handlers for an event is simply not part of the abstraction of events. Exactly how they're stored is an implementation detail - just like how the value for a property may be stored in a field, or it may be computed on-demand (e.g. from multiple fields).
Within a class exposing an event, you can normally access the invocation list (because you can determine how the event is implemented), but it's not information that's available "from the outside".
See more on this question at Stackoverflow