using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace Tango.Core { /// /// Represents a blocking concurrent queue for a producer consumer multi threading scenario. /// /// /// public class ProducerConsumerQueue : BlockingCollection { /// /// Initializes a new instance of the ProducerConsumerQueue, Use Add and TryAdd for Enqueue and TryEnqueue and Take and TryTake for Dequeue and TryDequeue functionality /// public ProducerConsumerQueue() : base(new ConcurrentQueue()) { } /// /// Initializes a new instance of the ProducerConsumerQueue, Use Add and TryAdd for Enqueue and TryEnqueue and Take and TryTake for Dequeue and TryDequeue functionality /// /// public ProducerConsumerQueue(int maxSize) : base(new ConcurrentQueue(), maxSize) { } /// /// Enqueues the specified item. /// /// The item. public void BlockEnqueue(T item) { Add(item); } /// /// Blocks until an item is available for dequeuing. /// /// public T BlockDequeue() { return Take(); } /// /// Blocks until an item is available for dequeuing. /// /// The cancellation token. /// public T BlockDequeue(CancellationToken cancellationToken) { return Take(cancellationToken); } } }