How to empty a BlockingCollection

前端 未结 6 2430
闹比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 22:09

    Possibly use the overload of GetConsumingEnumerable that takes a CancellationToken; then, if anything goes wrong from the producing side, it can cancel the consumer.

提交回复
热议问题