How to empty a BlockingCollection

前端 未结 6 2422
闹比i
闹比i 2021-02-18 21:34

I have a thread adding items to a BlockingCollection .

On another thread I am using foreach (var item in myCollection.GetConsumingEnumerable())

6条回答
  •  天命终不由人
    2021-02-18 21:48

    For just clearing the collection you can do:

    myBlockingCollection.TakeWhile<*MyObject*>(qItem => qItem != null);
    

    or just

    myBlockingCollection.TakeWhile<*MyObject*>(qItem => true);
    

提交回复
热议问题