BlockingCollection<T>.Take 方法

定義

BlockingCollection<T> 移除項目。Removes an item from the BlockingCollection<T>.

多載

Take()

BlockingCollection<T> 移除項目。Removes an item from the BlockingCollection<T>.

Take(CancellationToken)

BlockingCollection<T> 移除項目。Removes an item from the BlockingCollection<T>.

Take()

BlockingCollection<T> 移除項目。Removes an item from the BlockingCollection<T>.

public:
 T Take();
public T Take ();
member this.Take : unit -> 'T
Public Function Take () As T

傳回

T

從集合中移除的項目。The item removed from the collection.

例外狀況

基礎集合在這個 BlockingCollection<T> 執行個體以外修改,或者 BlockingCollection<T> 是空的且集合已標記為完成可供加入。The underlying collection was modified outside of this BlockingCollection<T> instance, or the BlockingCollection<T> is empty and the collection has been marked as complete for adding.

BlockingCollection<T> 是空的,且已被標記為已完成新增。The BlockingCollection<T> is empty and has been marked as complete with regards to additions.

備註

Take 的呼叫可能會封鎖,直到可以移除專案為止。A call to Take may block until an item is available to be removed.

項目的移除順序取決於用來建立 BlockingCollection<T> 執行個體的集合型別。The order in which an item is removed depends on the type of collection used to create the BlockingCollection<T> instance. 建立 BlockingCollection<T> 物件時,您可以指定要使用的集合型別。When you create a BlockingCollection<T> object, you can specify the type of collection to use. 例如,您可以針對先進先出 (FIFO) 行為指定 ConcurrentQueue<T> 物件,或針對後進先出 (LIFO) 行為指定 ConcurrentStack<T> 物件。For example, you could specify a ConcurrentQueue<T> object for first in, first out (FIFO) behavior, or a ConcurrentStack<T> object for last in, first out (LIFO) behavior. 您可以使用任何可實作 IProducerConsumerCollection<T> 介面的集合類別。You can use any collection class that implements the IProducerConsumerCollection<T> interface. BlockingCollection<T> 的預設集合類型為 ConcurrentQueue<T>The default collection type for BlockingCollection<T> is ConcurrentQueue<T>.

另請參閱

Take(CancellationToken)

BlockingCollection<T> 移除項目。Removes an item from the BlockingCollection<T>.

public:
 T Take(System::Threading::CancellationToken cancellationToken);
public T Take (System.Threading.CancellationToken cancellationToken);
member this.Take : System.Threading.CancellationToken -> 'T

參數

cancellationToken
CancellationToken

物件,可用來取消取得作業。Object that can be used to cancel the take operation.

傳回

T

從集合中移除的項目。The item removed from the collection.

例外狀況

已處置 BlockingCollection<T> 或取消建立語彙基元的 CancellationTokenSourceThe BlockingCollection<T> has been disposed or the CancellationTokenSource that created the token was canceled.

已在這個 BlockingCollection<T> 執行個體以外修改基礎集合,或者將 BlockingCollection 標記為完成可供加入,否則 BlockingCollection<T> 是空的。The underlying collection was modified outside of this BlockingCollection<T> instance or the BlockingCollection is marked as complete for adding, or the BlockingCollection<T> is empty.

備註

Take 的呼叫可能會封鎖,直到可以移除專案或解除標記為止。A call to Take may block until an item is available to be removed or the token is canceled.

項目的移除順序取決於用來建立 BlockingCollection<T> 執行個體的集合型別。The order in which an item is removed depends on the type of collection used to create the BlockingCollection<T> instance. 建立 BlockingCollection<T> 物件時,您可以指定要使用的集合型別。When you create a BlockingCollection<T> object, you can specify the type of collection to use. 例如,您可以針對先進先出 (FIFO) 行為指定 ConcurrentQueue<T> 物件,或針對後進先出 (LIFO) 行為指定 ConcurrentStack<T> 物件。For example, you could specify a ConcurrentQueue<T> object for first in, first out (FIFO) behavior, or a ConcurrentStack<T> object for last in, first out (LIFO) behavior. 您可以使用任何可實作 IProducerConsumerCollection<T> 介面的集合類別。You can use any collection class that implements the IProducerConsumerCollection<T> interface. BlockingCollection<T> 的預設集合類型為 ConcurrentQueue<T>The default collection type for BlockingCollection<T> is ConcurrentQueue<T>.

另請參閱

適用於