How to remove all Items from ConcurrentBag?

前端 未结 6 1122
猫巷女王i
猫巷女王i 2021-01-31 13:30

How to clear the ConcurrentBag? it don\'t have any method like Clear or RemoveAll...

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-31 13:46

    int cnt = _queue.Count;
    for (; cnt > 0; cnt--)
    {
         _queue.TryDequeue(out img);
    }
    

    It does not fall into an infinite loop, and clears the contents of the present time.

提交回复
热议问题