private void Consumer() { while (true) { IWork <string> work = null; lock (_locker) { while (Queue.Count == 0) { Monitor.Wait(_locker); } work = Queue.Dequeue(); if (work == null) { return; } work.Run(); } } }
/// <summary> /// Consumes this instance. /// </summary> void Consume() { while (!disposed) { lock (_locker) { while (_workQueue.Count == 0) { Monitor.Wait(_locker); } try { bool ok = _workQueue.TryDequeue(out currentWork); if (!ok) { throw new Exception("Try dequeue returns false"); } currentWork.Run(); } catch (Exception e) { #if DEBUG Debugger.Break(); #endif } finally { currentWork = null; } } } }