I\'m using Pipelines pattern implementation to decouple messages consumer from a producer to avoid slow-consumer issue.
In case of any exception on a message processi
BlockingCollection
is a wrapper around IProducerConsumerCollection
, which is more generic than e.g. ConcurrentQueue
and gives the implementer the freedom of not having to implement a (Try)Peek
method.
However, you can always call TryPeek
on the underlying queue directly:
ConcurrentQueue useOnlyForPeeking = new ConcurrentQueue();
BlockingCollection blockingCollection = new BlockingCollection(useOnlyForPeeking);
...
useOnlyForPeeking.TryPeek(...)
Note however that you must not modify your queue via useOnlyForPeeking
, otherwise blockingCollection
will get confused and may throw InvalidOperationExceptions at you, but I'd be surprised if calling the non-modifying TryPeek
on this concurrent data structure would be an issue.