I think following class would be optimal,
BlockingCollection<T>
Class
Provides blocking and bounding capabilities for thread-safe collections that implement IProducerConsumerCollection.
It acts as concurrent queue and you can process items async using Tasks.
Alternative would be ConcurrentQueue<T>
, But The BlockingCollection gives you two important features
It's thread-safe
When you call Take()
, it will block(i.e. wait until something is in the queue) for you, so you don't have to write any code with ManualResetEvents and the like, which is a nice simplification.