Is there a way to get number of attached event handlers to event? The problem is that somewhere in code it continues to attach handlers to an event, how can this be solved?
It is possible to get a list of all subscribers by calling GetInvocationList()
public class Foo
{
public int GetSubscriberCount()
{
var count = 0;
var eventHandler = this.CustomEvent;
if(eventHandler != null)
{
count = eventHandler.GetInvocationList().Length;
}
return count;
}
public event EventHandler CustomEvent;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With