Export (0) Print
Expand All

DataflowBlock.Choose<T1, T2> Method (ISourceBlock<T1>, Action<T1>, ISourceBlock<T2>, Action<T2>)

.NET Framework 4.5

Monitors two dataflow sources, invoking the provided handler for whichever source makes data available first.

Namespace:  System.Threading.Tasks.Dataflow
Assembly:  System.Threading.Tasks.Dataflow (in System.Threading.Tasks.Dataflow.dll)

public static Task<int> Choose<T1, T2>(
	ISourceBlock<T1> source1,
	Action<T1> action1,
	ISourceBlock<T2> source2,
	Action<T2> action2
)

Type Parameters

T1

Specifies type of data contained in the first source.

T2

Specifies type of data contained in the second source.

Parameters

source1
Type: System.Threading.Tasks.Dataflow.ISourceBlock<T1>

The first source.

action1
Type: System.Action<T1>

The handler to execute on data from the first source.

source2
Type: System.Threading.Tasks.Dataflow.ISourceBlock<T2>

The second source.

action2
Type: System.Action<T2>

The handler to execute on data from the second source.

Return Value

Type: System.Threading.Tasks.Task<Int32>
A Task<TResult> that represents the asynchronous choice. If both sources are completed prior to the choice completing, the resulting task will be canceled. When one of the sources has data available and successfully propagates it to the choice, the resulting task will complete when the handler completes; if the handler throws an exception, the task will end in the Faulted state and will contain the unhandled exception. Otherwise, the task will end with its Result set to either 0 or 1 to represent the first or second source, respectively.
This method will only consume an element from one of the two data sources, never both.

ExceptionCondition
ArgumentNullException

The source1 is null.

-or-

The action1 is null.

-or-

The source2 is null.

-or-

The action2 is null.

.NET Framework

Supported in: 4.5

Portable Class Library

Supported in: Portable Class Library

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft