Multiple consumers and querying a C# BlockingCollection

后端 未结 2 479
半阙折子戏
半阙折子戏 2021-02-05 08:14

I am using a .NET 4.0 BlockingCollection to handle a queue of items that each need to be processed by an operation that can take up to a second to process each item. This queue

2条回答
  •  后悔当初
    2021-02-05 08:39

    Multiple consumers can just call Take or TryTake concurrently - each item will only be consumed by a single consumer.

    However, I believe GetConsumingEnumerable will also do what you want. I believe if each caller calls that, each will get a separate consuming enumerable, which again will make sure that each item is only consumed once. I'm not sure offhand what happens when the queue becomes empty - I don't know whether MoveNext() then blocks, or returns false.

    I didn't really follow your second question though...

提交回复
热议问题