Use a BlockingCollection
to wrap the ConcurrentQueue
(the default backing store for a BlockingCollection
is a ConcurrentQueue
, so you don't even need to be explicit about it.
This allows you to write the consumer as:
foreach(var item in queue.GetConsumingEnumerable())
Process(item);