Is it possible to have a BlockingCollection<T>
(JobQueue
in my example) block execution on both the GetConsumingEnumerable()
stream AND on some other criteria?
I have the condition availableSlots > 0
which only allows items to be consumed when there are available slots. The problem is that the foreach indefinitely loops when there are items in the collection but the condition is false.
Can I not get the collection to block on availableSlots > 0
as well?
foreach (var job in JobQueue.GetConsumingEnumerable())
{
if(availableSlots > 0)
{
JobHandler jobHandler = job;
Task.Factory.StartNew(() =>
{
ExecuteJob(jobHandler);
});
}
}
Perhaps I am using this collection incorrectly. Any help appreciated!