How do i limit the number of event subscriptions when raised by an event aggregator?
-
12-12-2019 - |
Question
I need to limit the number of subscriptions for an event raised using event aggregator , How do i accomplish this?
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