BlockingCollection<T>.TryAddToAny Method

Definition

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

Overloads

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

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

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

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)

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

TryAddToAny(BlockingCollection<T>[], T)

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

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

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

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
Public Shared Function TryAddToAny (collections As BlockingCollection(Of T)(), item As T, millisecondsTimeout As Integer, 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.

millisecondsTimeout
Int32

The number of milliseconds to wait for the collection to accept the item, or Infinite (-1) to wait indefinitely.

cancellationToken
CancellationToken

A cancellation token to observe.

Returns

The index of the collection in the collections array to which the item was added, or -1 if the item could not be added.

Exceptions

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

The collections argument is null.

millisecondsTimeout is a negative number other than -1, which represents an infinite time-out.

-or-

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.

See also

Applies to

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

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

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

Parameters

collections
BlockingCollection<T>[]

The array of collections.

item
T

The item to be added to one of the collections.

timeout
TimeSpan

A TimeSpan that represents the number of milliseconds to wait, or a TimeSpan that represents -1 milliseconds to wait indefinitely.

Returns

The index of the collection in the collections array to which the item was added, or -1 if the item could not be added.

Exceptions

At least one of the BlockingCollection<T> instances or the CancellationTokenSource that created cancellationToken has been disposed.

The collections argument is null.

timeout is a negative number other than -1 milliseconds, which represents an infinite time-out.

-or-

timeout is greater than Int32.MaxValue.

-or-

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

This method can return early if the cancellationToken is cancelled before space was available for the Add operation.

See also

Applies to

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

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

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

Parameters

collections
BlockingCollection<T>[]

The array of collections.

item
T

The item to be added to one of the collections.

millisecondsTimeout
Int32

The number of milliseconds to wait for the collection to accept the item, or Infinite (-1) to wait indefinitely.

Returns

The index of the collection in the collections array to which the item was added, or -1 if the item could not be added.

Exceptions

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

The collections argument is null.

millisecondsTimeout is a negative number other than -1, which represents an infinite time-out.

-or-

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.

See also

Applies to

TryAddToAny(BlockingCollection<T>[], T)

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

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

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, or -1 if the item could not be 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.

See also

Applies to