You can use the BlockingCollection class to support multiple producers and one consumer.
Create an object of type BlockingCollection as follows:
BlockingCollection<object> collection = new BlockingCollection<object>();
Manufacturers can simply call the Add method to add an item to the collection as follows:
collection.Add("value");
And the consumer can use the GetConsumingEnumerable method to get an IEnumerable<T> that takes elements from the collection. Such an enumerated block will block (wait for more items) when there are no more items. This method also supports cancellation .
foreach (var item in collection.GetConsumingEnumerable()) {
If you call CompleteAdding , then the enumerated consumption will be completed if there are no more elements.
This class is completely thread safe.
source share