❔ What is the best approach for a process ConcurrentQueue?
I have a ConcurrentQueue which is filled by different threads. There is also a class that should, while there are elements in the queue, get the front one and process it. What is the best way to implement this? I only have this idea: In a loop with a timer, check if there are elements in the queue and if so, start processing the queue. Is there a better approach?
4 Replies
Why not use a BlockingCollection (which uses a ConcurrentQueue internally)
BlockingCollection.GetConsumingEnumerable Method (System.Collection...
Provides a consuming IEnumerable for items in the collection.
Thank you very much! It's just what I need.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.