protected virtual void OnTimerElapsed(TimeoutTimer timer) { }
void EventLoop() { Console.WriteLine("Started event queue worker"); try { foreach (object evt in InputQueue.GetConsumingEnumerable()) { if (evt == null) { continue; } if (!IsStarted) { return; } /// timers are TimeoutTimer TimeoutTimer timer = evt as TimeoutTimer; if (timer != null) { OnTimerElapsed(timer); } // strings are commands string command = evt as string; if (command != null) { OnCommandReceived(command); } // channels as tuples var channelEvent = evt as Tuple <INetworkSocket, bool>; if (channelEvent != null) { if (IsStarted) { if (channelEvent.Item2 == false) // channel removing = false { OnChannelCreated(channelEvent.Item1); } else { OnChannelDestroyed(channelEvent.Item1); } } } // MessageReceived(null, evt); InboundMessage message = evt as InboundMessage; if (message != null) { OnMessageReceived(message.SourceChannel, message.Message); } } } catch (OperationCanceledException) { Console.WriteLine("OperationCanceledException {0}", Id); } Console.Write("Worker finished"); }