Search code examples
c#concurrencyproducer-consumerconcurrent-queue

Try Dequeue in ConcurrentQueue


The TryDequeue in ConcurrentQueue<T> will return false if no items in queue.

If the queue is empty I need that my queue will wait until new item to be added in queue and it dequeue that new one, and the process will continues like that.

Should I use Monitor.Enter, Wait, Pulse or any better options in C# 4.0?


Solution

  • Isn't this what BlockingCollection is designed for?

    As I understand it, you can wrap your ConcurrentQueue with one of these, and then call Take.