快速和最佳生产者/消费者队列技术BlockingCollection vs并发队列 [英] Fast and Best Producer/consumer queue technique BlockingCollection vs concurrent Queue

查看:1063
本文介绍了快速和最佳生产者/消费者队列技术BlockingCollection vs并发队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Im在C#3.0和Monitor.Enter中使用Generic.Queue,等待,在消耗队列之前等待退出(等待元素入队)。现在我搬到C#4。



任何人都可以建议我哪个是最快,最好的,尤其是避免锁。



BlockingCollection vs concurrentQueue或任何其他...



注意。

解决方案

p> BlockingCollection ConcurrentQueue 正是出于这个原因。我怀疑你会发现更好的,或更简单的使用。并行扩展团队知道他们的东西:)



只是快速检查版本,虽然 - 你肯定使用.NET 4,而不只是C#4? (例如,您可以使用Visual Studio 2010和C#4,但仍然定位到.NET 3.5,在这种情况下,您不能使用并行扩展。)



您还可以开始研究基于任务的异步模式 TPL数据流 async / await功能C# 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..

解决方案

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 :)

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 vs并发队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆