BlockingCollection<T>.AddToAny 方法

定義

將指定的項目加入至任何一個指定的 BlockingCollection<T> 執行個體。Adds the specified item to any one of the specified BlockingCollection<T> instances.

多載

AddToAny(BlockingCollection<T>[], T)

將指定的項目加入至任何一個指定的 BlockingCollection<T> 執行個體。Adds the specified item to any one of the specified BlockingCollection<T> instances.

AddToAny(BlockingCollection<T>[], T, CancellationToken)

將指定的項目加入至任何一個指定的 BlockingCollection<T> 執行個體。Adds the specified item to any one of the specified BlockingCollection<T> instances.

AddToAny(BlockingCollection<T>[], T)

將指定的項目加入至任何一個指定的 BlockingCollection<T> 執行個體。Adds the specified item to any one of the specified BlockingCollection<T> instances.

public:
 static int AddToAny(cli::array <System::Collections::Concurrent::BlockingCollection<T> ^> ^ collections, T item);
public static int AddToAny (System.Collections.Concurrent.BlockingCollection<T>[] collections, T item);
static member AddToAny : System.Collections.Concurrent.BlockingCollection<'T>[] * 'T -> int
Public Shared Function AddToAny (collections As BlockingCollection(Of T)(), item As T) As Integer

參數

collections
BlockingCollection<T>[]

集合的陣列。The array of collections.

item
T

要加入至其中一個集合的項目。The item to be added to one of the collections.

傳回

collections 陣列中集合的索引,即其中加入了項目的索引。The index of the collection in the collections array to which the item was added.

例外狀況

至少其中一個 BlockingCollection<T> 執行個體已經處置。At least one of the BlockingCollection<T> instances has been disposed.

collections 引數為 null。The collections argument is null.

collections 的計數大於 STA 的上限 62 和 MTA 的上限 63。The count of collections is greater than the maximum size of 62 for STA and 63 for MTA.

collections 引數是長度為 0 的陣列,或包含 Null 項目,或至少其中一個集合已標記為完成加入。The collections argument is a 0-length array or contains a null element, or at least one of collections has been marked as complete for adding.

至少一個基礎集合不接受此項目。At least one underlying collection didn't accept the item.

備註

當所有 BlockingCollection<T> 實例都已初始化時,如果指定了限定容量,則 AddToAny 的呼叫可能會封鎖,直到其中一個集合中有可用空間可儲存所提供的專案為止。If a bounded capacity was specified when all of the BlockingCollection<T> instances were initialized, a call to AddToAny may block until space is available in one of the collections to store the provided item.

另請參閱

AddToAny(BlockingCollection<T>[], T, CancellationToken)

將指定的項目加入至任何一個指定的 BlockingCollection<T> 執行個體。Adds the specified item to any one of the specified BlockingCollection<T> instances.

public:
 static int AddToAny(cli::array <System::Collections::Concurrent::BlockingCollection<T> ^> ^ collections, T item, System::Threading::CancellationToken cancellationToken);
public static int AddToAny (System.Collections.Concurrent.BlockingCollection<T>[] collections, T item, System.Threading.CancellationToken cancellationToken);
static member AddToAny : System.Collections.Concurrent.BlockingCollection<'T>[] * 'T * System.Threading.CancellationToken -> int

參數

collections
BlockingCollection<T>[]

集合的陣列。The array of collections.

item
T

要加入至其中一個集合的項目。The item to be added to one of the collections.

cancellationToken
CancellationToken

要觀察的取消語彙基元。A cancellation token to observe.

傳回

collections 陣列中集合的索引,即其中加入了項目的索引。The index of the collection in the collections array to which the item was added.

例外狀況

至少一個基礎集合不接受此項目。At least one underlying collection didn't accept the item.

collections 引數為 null。The collections argument is null.

collections 的計數大於 STA 的上限 62 和 MTA 的上限 63。The count of collections is greater than the maximum size of 62 for STA and 63 for MTA.

collections 引數是長度為 0 的陣列,或包含 Null 項目,或至少其中一個集合已標記為完成加入。The collections argument is a 0-length array or contains a null element, or at least one of collections has been marked as complete for adding.

至少已經處置其中一個 BlockingCollection<T> 執行個體,或已處置建立 cancellationTokenCancellationTokenSourceAt least one of the BlockingCollection<T> instances has been disposed, or the CancellationTokenSource that created cancellationToken has been disposed.

備註

當所有 BlockingCollection<T> 實例都已初始化時,如果指定了限定容量,則 AddToAny 的呼叫可能會封鎖,直到其中一個集合中有可用空間可儲存所提供的專案為止。If a bounded capacity was specified when all of the BlockingCollection<T> instances were initialized, a call to AddToAny may block until space is available in one of the collections to store the provided item. 如果在空間可供使用之前取消 cancellationToken,這個方法可能會在將專案新增至任何集合之前傳回。This method may return before the item is added to any collection if the cancellationToken is canceled before space is available.

另請參閱

適用於