我知道有四种 Select .
第一个是Channels,它提供了一个支持异步Read
和Write
操作的线程安全队列.通道经过高度优化,如果达到阈值,可以 Select 删除一些项目.
下一个是TPL Dataflow比BufferBlock<T>
.如果你只有一个消费者,你可以使用OutputAvailableAsync
或ReceiveAsync
,或者只是将其链接到ActionBlock<T>
.欲了解更多信息,请点击see my blog.
最后两个是我创建的类型,在我的AsyncEx library中提供.
AsyncCollection<T>
is the async
near-equivalent of BlockingCollection<T>
, capable of wrapping a concurrent producer/consumer collection such as ConcurrentQueue<T>
or ConcurrentBag<T>
. You can use TakeAsync
to asynchronously consume items from the collection. For more information, see my blog.
AsyncProducerConsumerQueue<T>
is a more portable async
-compatible producer/consumer queue. You can use DequeueAsync
to asynchronously consume items from the queue. For more information, see my blog.
这些备选方案中的最后三个允许同步和异步放置和获取.