TryTakeFromAny Method (BlockingCollection(T)[], T, Int32)

Task Parallel System.Threading

Attempts to remove an item from any one of the specified BlockingCollection<(Of <(T>)>) instances.

Namespace:  System.Collections.Concurrent
Assembly:  System.Threading (in System.Threading.dll)

Syntax

Visual Basic (Declaration)
Public Shared Function TryTakeFromAny ( _
	collections As BlockingCollection(Of T)(), _
	<OutAttribute> ByRef item As T, _
	millisecondsTimeout As Integer _
) As Integer
C#
public static int TryTakeFromAny(
	BlockingCollection<T>[] collections,
	out T item,
	int millisecondsTimeout
)

Parameters

collections
Type: array< System.Collections.Concurrent..::.BlockingCollection<(Of <(T>)>) >[]()[]
The array of collections.
item
Type: T %
The item removed from one of the collections.
millisecondsTimeout
Type: System..::.Int32
The number of milliseconds to wait, or Infinite (-1) to wait indefinitely.

Return Value

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

Remarks

A call to TryTakeFromAny may block until an item is available to be removed.

Exceptions

ExceptionCondition
System..::.ArgumentNullExceptionThe collections argument is null.
System..::.ArgumentExceptionThe collections argument is a 0-length array or contains a null element.
System..::.ObjectDisposedExceptionAt least one of the BlockingCollection<(Of <(T>)>) instances has been disposed.
System..::.ArgumentOutOfRangeExceptionmillisecondsTimeout is a negative number other than -1, which represents an infinite time-out.
System..::.InvalidOperationExceptionAt least one of the underlying collections was modified outside of its BlockingCollection<(Of <(T>)>) instance.
System..::.ArgumentOutOfRangeExceptionThe count of collections is greater than the maximum size of 62 for STA and 63 for MTA.

See Also