I have a thread adding items to a BlockingCollection .
BlockingCollection
On another thread I am using foreach (var item in myCollection.GetConsumingEnumerable())
foreach (var item in myCollection.GetConsumingEnumerable())
This worked for me
while (bCollection.Count > 0) { var obj = bCollection.Take(); obj.Dispose(); }
Take() removes from the collection and you can call any clean up on your object and the loop condition does not invoke any blocking calls.
Take()