C#: need a blocking FIFO queue similar to Java's LinkedBlockingQueue

匿名 (未验证) 提交于 2019-12-03 03:10:03

问题:

need something similiar with java's LinkedBlockingQueue.

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 must be FIFO

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

回答1:

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.

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!