C#: need a blocking FIFO queue similar to Java#39;s LinkedBlockingQueue(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 队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C#:需要一个类似于 Java 的 LinkedBlockingQueue 的阻塞 FIFO 队列


基础教程推荐
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01