快速和最佳生产者/消费者队列技术BlockingCollection vs并发队列

编程入门 行业动态 更新时间:2024-10-10 15:18:26
本文介绍了快速和最佳生产者/消费者队列技术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并发队列

本文发布于:2023-11-26 09:20:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633539.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:队列   生产者   消费者   快速   技术

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!