BlockingCollection<T>.TryAddToAny 方法

定義

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

多載

TryAddToAny(BlockingCollection<T>[], T, Int32, CancellationToken)

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

TryAddToAny(BlockingCollection<T>[], T, TimeSpan)

當觀察指定的取消語彙基元時,嘗試將指定的項目加入任何一個指定的 BlockingCollection<T> 執行個體。Tries to add the specified item to any one of the specified BlockingCollection<T> instances while observing the specified cancellation token.

TryAddToAny(BlockingCollection<T>[], T, Int32)

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

TryAddToAny(BlockingCollection<T>[], T)

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

TryAddToAny(BlockingCollection<T>[], T, Int32, CancellationToken)

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

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

參數

collections
BlockingCollection<T>[]

集合的陣列。The array of collections.

item
T

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

millisecondsTimeout
Int32

要等候的毫秒數,如果要無限期等候,則為 Infinite (-1)。The number of milliseconds to wait, or Infinite (-1) to wait indefinitely.

cancellationToken
CancellationToken

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

傳回

要在其中加入項目的 collections 陣列中集合的索引,如果無法加入項目則為 -1。The index of the collection in the collections array to which the item was added, or -1 if the item could not be added.

例外狀況

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

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

millisecondsTimeout 為 -1 以外的負數,表示無限逾時。millisecondsTimeout is a negative number other than -1, which represents an infinite time-out. -或--or- 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> 執行個體已經處置。At least one of the BlockingCollection<T> instances has been disposed.

另請參閱

TryAddToAny(BlockingCollection<T>[], T, TimeSpan)

當觀察指定的取消語彙基元時,嘗試將指定的項目加入任何一個指定的 BlockingCollection<T> 執行個體。Tries to add the specified item to any one of the specified BlockingCollection<T> instances while observing the specified cancellation token.

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

參數

collections
BlockingCollection<T>[]

集合的陣列。The array of collections.

item
T

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

timeout
TimeSpan

TimeSpan,代表等候毫秒數;或是 TimeSpan,代表無限期等候的 -1 毫秒。A TimeSpan that represents the number of milliseconds to wait, or a TimeSpan that represents -1 milliseconds to wait indefinitely.

傳回

要在其中加入項目的 collections 陣列中集合的索引,如果無法加入項目則為 -1。The index of the collection in the collections array to which the item was added, or -1 if the item could not be added.

例外狀況

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

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

timeout 是除了 -1 毫秒以外的負數,表示無限逾時,或是大於 MaxValue 的逾時。timeout is a negative number other than -1 milliseconds, which represents an infinite time-out -or- timeout is greater than MaxValue.

-或--or- 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.

備註

如果在可供加入作業使用空間之前取消 cancellationToken,這個方法可能會提早傳回。This method can return early if the cancellationToken is cancelled before space was available for the Add operation.

另請參閱

TryAddToAny(BlockingCollection<T>[], T, Int32)

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

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

參數

collections
BlockingCollection<T>[]

集合的陣列。The array of collections.

item
T

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

millisecondsTimeout
Int32

要等候的毫秒數,如果要無限期等候,則為 Infinite (-1)。The number of milliseconds to wait, or Infinite (-1) to wait indefinitely.

傳回

要在其中加入項目的 collections 陣列中集合的索引,如果無法加入項目則為 -1。The index of the collection in the collections array to which the item was added, or -1 if the item could not be added.

例外狀況

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

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

millisecondsTimeout 為 -1 以外的負數,表示無限逾時。millisecondsTimeout is a negative number other than -1, which represents an infinite time-out. -或--or- 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.

另請參閱

TryAddToAny(BlockingCollection<T>[], T)

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

public:
 static int TryAddToAny(cli::array <System::Collections::Concurrent::BlockingCollection<T> ^> ^ collections, T item);
public static int TryAddToAny (System.Collections.Concurrent.BlockingCollection<T>[] collections, T item);
static member TryAddToAny : System.Collections.Concurrent.BlockingCollection<'T>[] * 'T -> int
Public Shared Function TryAddToAny (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 陣列中集合的索引,如果無法加入項目則為 -1。The index of the collection in the collections array to which the item was added, or -1 if the item could not be 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.

另請參閱

適用於