public bool Subscribe(SubscriptionToken subscriptionToken) { if (subscriptionToken == null) { throw new ArgumentNullException(nameof(subscriptionToken)); } if (!Subscribtions.Contains(subscriptionToken)) { Subscribtions.Add(subscriptionToken); return true; } return false; }
static void Main(string[] args) { var router = new Router(); var broadcast = new BroadcastToken("TimerBroadcast", null, null); router.AddBroadcast(new BroadcastToken("TimerBroadcast", null, null)); var subscription = new SubscriptionToken(null, handler, broadcastType: typeof(BroadcastToken)); router.Subscribe(subscription); Timer timer = new Timer(); timer.Interval = 5000; timer.Elapsed += broadcast.Broadcast; timer.Start(); new ManualResetEvent(false).WaitOne(); }