DataflowBlock.ReceiveAsync Method

Definition

Overloads

ReceiveAsync<TOutput>(ISourceBlock<TOutput>)

Asynchronously receives a value from a specified source.

ReceiveAsync<TOutput>(ISourceBlock<TOutput>, CancellationToken)

Asynchronously receives a value from a specified source and provides a token to cancel the operation.

ReceiveAsync<TOutput>(ISourceBlock<TOutput>, TimeSpan)

Asynchronously receives a value from a specified source, observing an optional time-out period.

ReceiveAsync<TOutput>(ISourceBlock<TOutput>, TimeSpan, CancellationToken)

Asynchronously receives a value from a specified source, providing a token to cancel the operation and observing an optional time-out interval.

ReceiveAsync<TOutput>(ISourceBlock<TOutput>)

Source:
DataflowBlock.cs
Source:
DataflowBlock.cs
Source:
DataflowBlock.cs
Source:
DataflowBlock.cs

Asynchronously receives a value from a specified source.

C#
public static System.Threading.Tasks.Task<TOutput> ReceiveAsync<TOutput>(this System.Threading.Tasks.Dataflow.ISourceBlock<TOutput> source);

Type Parameters

TOutput

The type of data contained in the source.

Parameters

source
ISourceBlock<TOutput>

The source from which to receive the value.

Returns

Task<TOutput>

A task that represents the asynchronous receive operation. When an item value is successfully received from the source, the returned task is completed and its Result returns the received value. If an item value cannot be retrieved because the source is empty and completed , an InvalidOperationException exception is thrown in the returned task.

Exceptions

source is null.

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 (package-provided), 8, 9 (package-provided), 9, 10 (package-provided), 10
.NET Standard 2.0 (package-provided), 2.1 (package-provided)
UWP 10.0

ReceiveAsync<TOutput>(ISourceBlock<TOutput>, CancellationToken)

Source:
DataflowBlock.cs
Source:
DataflowBlock.cs
Source:
DataflowBlock.cs
Source:
DataflowBlock.cs

Asynchronously receives a value from a specified source and provides a token to cancel the operation.

C#
public static System.Threading.Tasks.Task<TOutput> ReceiveAsync<TOutput>(this System.Threading.Tasks.Dataflow.ISourceBlock<TOutput> source, System.Threading.CancellationToken cancellationToken);

Type Parameters

TOutput

Specifies the type of data contained in the source.

Parameters

source
ISourceBlock<TOutput>

The source from which to receive the value.

cancellationToken
CancellationToken

The token to use to cancel the receive operation.

Returns

Task<TOutput>

A task that represents the asynchronous receive operation. When a value is successfully received from the source, the returned task is completed and its Result returns the value. If a value cannot be retrieved because cancellation was requested, the returned task is canceled. If the value cannot be retrieved because the source is empty and completed , an InvalidOperationException exception is thrown in the returned task.

Exceptions

source is null.

The cancellation token was canceled. This exception is stored into the returned task.

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 (package-provided), 8, 9 (package-provided), 9, 10 (package-provided), 10
.NET Standard 2.0 (package-provided), 2.1 (package-provided)
UWP 10.0

ReceiveAsync<TOutput>(ISourceBlock<TOutput>, TimeSpan)

Source:
DataflowBlock.cs
Source:
DataflowBlock.cs
Source:
DataflowBlock.cs
Source:
DataflowBlock.cs

Asynchronously receives a value from a specified source, observing an optional time-out period.

C#
public static System.Threading.Tasks.Task<TOutput> ReceiveAsync<TOutput>(this System.Threading.Tasks.Dataflow.ISourceBlock<TOutput> source, TimeSpan timeout);

Type Parameters

TOutput

The type of data contained in the source.

Parameters

source
ISourceBlock<TOutput>

The source from which to receive the value.

timeout
TimeSpan

The maximum time interval, in milliseconds, to wait for the synchronous operation to complete, or an interval that represents -1 milliseconds to wait indefinitely.

Returns

Task<TOutput>

A task that represents the asynchronous receive operation. When a value is successfully received from the source, the returned task is completed and its Result returns the value. If a value cannot be retrieved because the time-out expired, the returned task is canceled. If the value cannot be retrieved because the source is empty and completed , an InvalidOperationException exception is thrown in the returned task.

Exceptions

source is null.

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

-or-

timeout is greater than Int32.MaxValue.

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 (package-provided), 8, 9 (package-provided), 9, 10 (package-provided), 10
.NET Standard 2.0 (package-provided), 2.1 (package-provided)
UWP 10.0

ReceiveAsync<TOutput>(ISourceBlock<TOutput>, TimeSpan, CancellationToken)

Source:
DataflowBlock.cs
Source:
DataflowBlock.cs
Source:
DataflowBlock.cs
Source:
DataflowBlock.cs

Asynchronously receives a value from a specified source, providing a token to cancel the operation and observing an optional time-out interval.

C#
public static System.Threading.Tasks.Task<TOutput> ReceiveAsync<TOutput>(this System.Threading.Tasks.Dataflow.ISourceBlock<TOutput> source, TimeSpan timeout, System.Threading.CancellationToken cancellationToken);

Type Parameters

TOutput

The type of data contained in the source.

Parameters

source
ISourceBlock<TOutput>

The source from which to receive the value.

timeout
TimeSpan

The maximum time interval, in milliseconds, to wait for the synchronous operation to complete, or an interval that represents -1 milliseconds to wait indefinitely.

cancellationToken
CancellationToken

The token which may be used to cancel the receive operation.

Returns

Task<TOutput>

A task that represents the asynchronous receive operation. When a value is successfully received from the source, the returned task is completed and its Result returns the value. If a value cannot be retrieved because the time-out expired or cancellation was requested, the returned task is canceled. If the value cannot be retrieved because the source is empty and completed, an InvalidOperationException exception is thrown in the returned task.

Exceptions

source is null.

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

-or-

timeout is greater than Int32.MaxValue.

The cancellation token was canceled. This exception is stored into the returned task.

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 (package-provided), 8, 9 (package-provided), 9, 10 (package-provided), 10
.NET Standard 2.0 (package-provided), 2.1 (package-provided)
UWP 10.0