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.

C#
public static int AddToAny(System.Collections.Concurrent.BlockingCollection<T>[] collections, T item);

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

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

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.

C#
public static int AddToAny(System.Collections.Concurrent.BlockingCollection<T>[] collections, T item, System.Threading.CancellationToken cancellationToken);

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

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0