public void Stop() { if (_status != MessageDispatcherStatus.Started) { return; } _status = MessageDispatcherStatus.Stopping; WaitUntilAllMessagesAreProcessed(); _status = MessageDispatcherStatus.Stopped; var stopTasks = _dispatchQueues.Values.Select(dispatchQueue => Task.Factory.StartNew(dispatchQueue.Stop)).ToArray(); Task.WaitAll(stopTasks); }
public void Start() { switch (_status) { case MessageDispatcherStatus.Started: return; case MessageDispatcherStatus.Stopping: throw new InvalidOperationException("MessageDispatcher is stopping"); } _status = MessageDispatcherStatus.Started; foreach (var dispatchQueue in _dispatchQueues.Values) { dispatchQueue.Start(); } }