循环通过BlockingCollection <t>而不消耗

时间:2017-10-31 09:12:59

标签: c# concurrency blockingcollection

在我的程序的生产者方面,在处理将要发送到集合的项目时,必须检查它们是否在队列中是否重复,所以我需要首先遍历BlockingCollection<ConcurrentQueue<Message>>地点。但我无法找到如何循环阻塞集合。

public BlockingCollection<ConcurrentQueue<Message>> Collection { get; set; } 
= new BlockingCollection<ConcurrentQueue<Message>>();

foreach(var item in Collection)
{
    //item is ConcurrentQueue<Message>
}

foreach (ConcurrentQueue<Message> queue in Collection)
{
    foreach (var item in queue)    
    {   
        //I don't know if it is efficient but I can reach like that
    }
}  

foreach(var item in Collection.Queue)
{
    // Is there an api something like that?
} 

0 个答案:

没有答案