How to remove a single, specific object from a ConcurrentBag<>?

后端 未结 9 497
误落风尘
误落风尘 2021-02-02 04:34

With the new ConcurrentBag in .NET 4, how do you remove a certain, specific object from it when only TryTake() and TryPeek() are

9条回答
  •  既然无缘
    2021-02-02 05:13

    You can't. Its a bag, it isn't ordered. When you put it back, you'll just get stuck in an endless loop.

    You want a Set. You can emulate one with ConcurrentDictionary. Or a HashSet that you protect yourself with a lock.

提交回复
热议问题