I have a thread adding items to a BlockingCollection
.
On another thread I am using
foreach (var item in myCollection.GetConsumingEnumerable())
I'm using this extension method:
public static void Clear(this BlockingCollection blockingCollection)
{
if (blockingCollection == null)
{
throw new ArgumentNullException("blockingCollection");
}
while (blockingCollection.Count > 0)
{
T item;
blockingCollection.TryTake(out item);
}
}
I'm wondering if there's a better, less hacky, solution.