How can I create the parallel equivalent of a do
-while
or similar in the Update()
method below?
Another thread in the app writes to TestBuffer
at random. TestBuffer.RemoveItemAndDoSomethingWithIt();
should run until the TestBuffer
is empty. Currently Update()
only runs with the items that were in the collection when it was was enumerated, which makes sense.
internal class UnOrderedBuffer<T> where T : class
{
ConcurrentBag<T> GenericBag = new ConcurrentBag<T>();
}
internal class Tester
{
private UnOrderedBuffer<Data> TestBuffer;
public void Update()
{
Parallel.ForEach(TestBuffer, Item =>
{
TestBuffer.RemoveItemAndDoSomethingWithIt();
});
}
}