private async Task WatchQueue(int id) { Running = true; Alive[id] = true; while (Running) { if (queue.TryDequeue(out Message message)) { try { onDispatch(); message.Action(); } catch (Exception e) { var exception = new DispatcherException(message.Dispatchee, message.Trace, e); EnqueueException(exception); onException(e); } } else { await Task.Delay(pollingDelay); } } Alive[id] = false; }
private void EnqueueException(DispatcherException exception) { lock (faultLock) { if (faults.Count >= faultBufferSize) { faults.Dequeue(); } faults.Enqueue(exception); } }