开发者

Iterating ConcurrentQueue<T>

Is this a safe way of iterating ConcurrentQueu开发者_开发问答e<T>?

while (cq.GetEnumerator().MoveNext())
{
    IIndexTask task;
    if (cq.TryDequeue(out task))
        task.Execute(service);
}


Just do this instead...

IIndexTask task;
while (cq.TryDequeue(out task))
{
    task.Execute(service);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜