BlockingCollection<T>.AddToAny Method

Definition

Adds the specified item to any one of the specified BlockingCollection<T> instances.

Overloads

AddToAny(BlockingCollection<T>[], T)

Adds the specified item to any one of the specified BlockingCollection<T> instances.

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

Adds the specified item to any one of the specified BlockingCollection<T> instances.

AddToAny(BlockingCollection<T>[], T)

Source:
BlockingCollection.cs
Source:
BlockingCollection.cs
Source:
BlockingCollection.cs

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

Parameters

collections
BlockingCollection<T>[]

The array of collections.

item
T

The item to be added to one of the collections.

Returns

The index of the collection in the collections array to which the item was added.

Exceptions

At least one of the BlockingCollection<T> instances has been disposed.

The collections argument is null.

The count of collections is greater than the maximum size of 62 for STA and 63 for MTA.

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.

Remarks

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.

See also

Applies to

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

Source:
BlockingCollection.cs
Source:
BlockingCollection.cs
Source:
BlockingCollection.cs

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
Public Shared Function AddToAny (collections As BlockingCollection(Of T)(), item As T, cancellationToken As CancellationToken) As Integer

Parameters

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.

Returns

The index of the collection in the collections array to which the item was added.

Exceptions

At least one underlying collection didn't accept the item.

The collections argument is null.

The count of collections is greater than the maximum size of 62 for STA and 63 for MTA.

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 of the BlockingCollection<T> instances has been disposed, or the CancellationTokenSource that created cancellationToken has been disposed.

Remarks

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. This method may return before the item is added to any collection if the cancellationToken is canceled before space is available.

See also

Applies to