快速和最佳的生产者/消费者队列技术 BlockingCollection 与并发队列 [英] Fast and Best Producer/consumer queue technique BlockingCollection vs concurrent Queue
问题描述
我在 C# 3.0 中使用 Generic.Queue 和 Monitor.Enter,wait,exit for wait 在消费队列之前(等待元素入队).现在我正在转向 C# 4.
谁能告诉我哪一个是快速且最好的,尤其是避免锁定..
BlockingCollection 与 concurrentQueue 或其他任何东西...
注意.我不想限制我的制作人
提前致谢..
BlockingCollection
和 ConcurrentQueue
正是出于这个原因.我怀疑您会找到更好的或更易于使用的方法.并行扩展团队知道他们的东西:)
只是快速检查版本 - 您肯定在使用 .NET 4,而不仅仅是 C# 4?(例如,您可以使用 Visual Studio 2010 和 C# 4,但仍面向 .NET 3.5,在这种情况下,您不能使用并行扩展.)
您可能还想开始研究基于任务的异步模式, Im using Generic.Queue in C# 3.0 and Monitor.Enter,wait,exit for wait before consuming the queue (wait for the element to be enqueued). Now im moving to C# 4. Can anyone suggest me which one is fast and best especially to avoid locks.. BlockingCollection vs concurrentQueue or any thing else... Note. I dont want to restrict my producer Thanks in advance.. Just a quick check on versions though - you're definitely using .NET 4, not just C# 4? (For example, you could be using Visual Studio 2010 and thus C# 4, but still targeting .NET 3.5, in which case you couldn't use Parallel Extensions.) You may also want to start researching Task-Based Asynchronous Pattern, TPL Dataflow and the async/await features of C# 5... obviously you can't use them just yet, but it doesn't hurt to know what's coming up. 这篇关于快速和最佳的生产者/消费者队列技术 BlockingCollection 与并发队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!BlockingCollection
and ConcurrentQueue
are there for precisely this reason. I doubt that you'll find anything better, or simpler to use. The parallel extensions team know their stuff :)