Question

I need to limit the number of subscriptions for an event raised using event aggregator , How do i accomplish this?

Was it helpful?

Solution

You may check InvocationList.Count in add method of your event.

Something like this:

private EventHandler MyEventDel;       


   public event EventHandler ExplicitEvent
    {
        add
        {
            if (MyEventDel.GetInvocationList().Count() < 10)
            {
                MyEventDel+= value;
            }
        }
        remove
        {
            MyEventDel-= value;
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top