在BlockingCollection&LT元素的顺序

在BlockingCollection&LT元素的顺序

本文介绍了在BlockingCollection&LT元素的顺序;>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 BlockingCollection&LT实现的下载队列;> 。现在,我想在一段时间曾经有些优先下载。我想这可能是巨大的,将一些元素上的集合,就像一个列表,但没有办法像删除()/ AddFirst()或Move()。

I have a Download Queue implemented with BlockingCollection<>. Now I want to prioritize some Download once in a while. I thought it might be great to move some elements 'up' the Collection, like in a list, but there is no method like Remove()/AddFirst() or Move().

什么是安排项目的preferred方式 BlockingCollection&LT;&GT;

What's the preferred way of arranging items in a BlockingCollection<> ?

推荐答案

BlockingCollection&LT; T&GT; 就封装内部<$c$c>IProducerConsumerCollection<T>.默认值是使用 ConcurrentQueue&LT; T&GT; 内部,但是可以通过的。

BlockingCollection<T> works by wrapping an internal IProducerConsumerCollection<T>. The default is to use a ConcurrentQueue<T> internally, but you can provide your own implementation via this constructor.

如果您提供自己的线程安全的集合,你可以使用任何你想要的集合类型。这将允许根据需要给你优先考虑的元素。

If you provide your own threadsafe collection, you can use any collection type you want. This would allow to you prioritize elements as needed.

虽然没有内置集合,将实现你想要的功能,你也许可以换一对 ConcurrentQueue&LT的; T&GT; 集合到一个类实现 IProducerConsumerCollection&LT; T&GT; 。这将让你有高优先级和低优先级的元素。

While there are no built-in collections that will implement your desired functionality, you could probably wrap a pair of ConcurrentQueue<T> collections into a class that implements IProducerConsumerCollection<T>. This would allow you to have "high priority" and "low priority" elements.

这篇关于在BlockingCollection&LT元素的顺序;&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 01:11