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);
}
精彩评论