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 队列


- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- 输入按键事件处理程序 2022-01-01