C#:需要一个类似于 Java 的 LinkedBlockingQueue 的阻塞 FIFO 队列 [英] C#: need a blocking FIFO queue similar to Java's LinkedBlockingQueue

查看:20
本文介绍了C#:需要一个类似于 Java 的 LinkedBlockingQueue 的阻塞 FIFO 队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要与 java 的 LinkedBlockingQueue 类似的东西.

need something similiar with java's LinkedBlockingQueue.

感兴趣的方法:messageQueue.poll(120000, TimeUnit.MILLISECONDS);意思是..尝试获取项目..如果在 X 单位时间内您仍然没有项目..返回 null

method of interest: messageQueue.poll(120000, TimeUnit.MILLISECONDS); meaning ..try to get item..and if in X unit of time you still have no item..return null

that + i 必须是 FIFO

that + i must be FIFO

经过一番谷歌搜索(但尚未测试):我发现 ConcurrentQueue(具有 FIFO 行为)、BlockingCollection(FiFO 或没有 FIFO??)

after some googling (but havent yet tested): i found ConcurrentQueue (has FIFO behaviour), BlockingCollection (FiFO OR no FIFO??)

推荐答案

BlockingCollection 可以与任意数量的不同类型的集合一起使用.如果您不手动传入特定类型的并发集合,它将使用 ConcurrentQueue,这意味着它将完全按照您的意愿进行操作.您可以使用并发堆栈类型,或根据需要使用并发优先级队列,这就是它使用通用名称(例如 Blocking Collection)而不是 BlockingConcurrentQueue 的原因.

BlockingCollection can be used with any number of different types of collections. If you don't manually pass in a specific type of concurrent collection it will uses a ConcurrentQueue, meaning it will do exactly what you want. You can uses a concurrent stack type, or a concurrent priority queue if you want, which is why it uses a general name such as Blocking Collection, and not BlockingConcurrentQueue.

如果您不想相信我的话,所有这些都列在了 BlockingCollection 的 MSDN 页面上.

All of this is listed on the MSDN page for BlockingCollection if you don't want to take my word for it.

这篇关于C#:需要一个类似于 Java 的 LinkedBlockingQueue 的阻塞 FIFO 队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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