tags:

views:

41

answers:

1

Assuming I have declared

public event EventArgs<SyslogMessageEventArgs> MessageReceived;

public int SubscribedClients
{
    get [...]
}

I would like to count how many "subscribed clients" my class has. I need to sum those that subscribed over network though my APIs (not shown in the fragment) plus those that did channel.MessageReceived+=myMethod;.

I know that C# events may be declared explicitly with add and remove statements, and there I can surely count + or -1 to a local counter, but I never wrote code for explicit events in C#, so I don't know exactly what more to perform on add and remove rather than updating the counter.

Thank you.

+6  A: 
MessageReceived.GetInvocationList().Length
Andrey
You'd better add a null test.
Hans Passant