DataflowBlock.ReceiveAsync 方法
定义
重载
| 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>)
异步接收来自指定源的值。Asynchronously receives a value from a specified source.
public:
generic <typename TOutput>
[System::Runtime::CompilerServices::Extension]
static System::Threading::Tasks::Task<TOutput> ^ ReceiveAsync(System::Threading::Tasks::Dataflow::ISourceBlock<TOutput> ^ source);
public static System.Threading.Tasks.Task<TOutput> ReceiveAsync<TOutput> (this System.Threading.Tasks.Dataflow.ISourceBlock<TOutput> source);
static member ReceiveAsync : System.Threading.Tasks.Dataflow.ISourceBlock<'Output> -> System.Threading.Tasks.Task<'Output>
<Extension()>
Public Function ReceiveAsync(Of TOutput) (source As ISourceBlock(Of TOutput)) As Task(Of TOutput)
类型参数
- TOutput
源中包含的数据的类型。The type of data contained in the source.
参数
- source
- ISourceBlock<TOutput>
从中接收值的源。The source from which to receive the value.
返回
- Task<TOutput>
表示异步接收操作的任务。A task that represents the asynchronous receive operation. 当从源成功检索出项值时,则返回项的任务将完成,并且其 Result 将返回接收的值。When an item value is successfully received from the source, the returned task is completed and its Result returns the received value. 如果因为源为空且已完成而无法检索项值,则返回的任务中会引发 InvalidOperationException 异常。If an item value cannot be retrieved because the source is empty and completed , an InvalidOperationException exception is thrown in the returned task.
例外
source 为 null。source is null.
适用于
ReceiveAsync<TOutput>(ISourceBlock<TOutput>, CancellationToken)
异步从指定的数据源中接收值并提供标记来取消操作。Asynchronously receives a value from a specified source and provides a token to cancel the operation.
public:
generic <typename TOutput>
[System::Runtime::CompilerServices::Extension]
static System::Threading::Tasks::Task<TOutput> ^ ReceiveAsync(System::Threading::Tasks::Dataflow::ISourceBlock<TOutput> ^ source, System::Threading::CancellationToken cancellationToken);
public static System.Threading.Tasks.Task<TOutput> ReceiveAsync<TOutput> (this System.Threading.Tasks.Dataflow.ISourceBlock<TOutput> source, System.Threading.CancellationToken cancellationToken);
static member ReceiveAsync : System.Threading.Tasks.Dataflow.ISourceBlock<'Output> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Output>
<Extension()>
Public Function ReceiveAsync(Of TOutput) (source As ISourceBlock(Of TOutput), cancellationToken As CancellationToken) As Task(Of TOutput)
类型参数
- TOutput
指定源中所包含的数据的类型。Specifies the type of data contained in the source.
参数
- source
- ISourceBlock<TOutput>
从中接收值的源。The source from which to receive the value.
- cancellationToken
- CancellationToken
用于取消接收操作的标记。The token to use to cancel the receive operation.
返回
- Task<TOutput>
表示异步接收操作的任务。A task that represents the asynchronous receive operation. 当从源成功检索出值时,则返回项的任务将完成,并且其 Result 将返回接值。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. 如果因为源为空且已完成而无法检索值,则返回的任务中会引发 InvalidOperationException 异常。If the value cannot be retrieved because the source is empty and completed , an InvalidOperationException exception is thrown in the returned task.
例外
source 为 null。source is null.
适用于
ReceiveAsync<TOutput>(ISourceBlock<TOutput>, TimeSpan)
异步从指定的数据源中接收值,观察可选的超时期限。Asynchronously receives a value from a specified source, observing an optional time-out period.
public:
generic <typename TOutput>
[System::Runtime::CompilerServices::Extension]
static System::Threading::Tasks::Task<TOutput> ^ ReceiveAsync(System::Threading::Tasks::Dataflow::ISourceBlock<TOutput> ^ source, TimeSpan timeout);
public static System.Threading.Tasks.Task<TOutput> ReceiveAsync<TOutput> (this System.Threading.Tasks.Dataflow.ISourceBlock<TOutput> source, TimeSpan timeout);
static member ReceiveAsync : System.Threading.Tasks.Dataflow.ISourceBlock<'Output> * TimeSpan -> System.Threading.Tasks.Task<'Output>
<Extension()>
Public Function ReceiveAsync(Of TOutput) (source As ISourceBlock(Of TOutput), timeout As TimeSpan) As Task(Of TOutput)
类型参数
- TOutput
源中包含的数据的类型。The type of data contained in the source.
参数
- source
- ISourceBlock<TOutput>
从中接收值的源。The source from which to receive the value.
- timeout
- TimeSpan
等待同步操作完成的最大时间间隔(以毫秒为单位),或表示 -1 毫秒无限期等待的时间间隔。The maximum time interval, in milliseconds, to wait for the synchronous operation to complete, or an interval that represents -1 milliseconds to wait indefinitely.
返回
- Task<TOutput>
表示异步接收操作的任务。A task that represents the asynchronous receive operation. 当从源成功检索出值时,则返回项的任务将完成,并且其 Result 将返回接值。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. 如果因为源为空且已完成而无法检索值,则返回的任务中会引发 InvalidOperationException 异常。If the value cannot be retrieved because the source is empty and completed , an InvalidOperationException exception is thrown in the returned task.
例外
source 为 null。source is null.
timeout 是一个非 -1 毫秒的负数,而 -1 表示无限期超时期限。timeout is a negative number other than -1 milliseconds, which represents an infinite time-out period.
- 或 --or-
timeout 大于 MaxValue。timeout is greater than MaxValue.
适用于
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.
public:
generic <typename TOutput>
[System::Runtime::CompilerServices::Extension]
static System::Threading::Tasks::Task<TOutput> ^ ReceiveAsync(System::Threading::Tasks::Dataflow::ISourceBlock<TOutput> ^ source, TimeSpan timeout, System::Threading::CancellationToken cancellationToken);
public static System.Threading.Tasks.Task<TOutput> ReceiveAsync<TOutput> (this System.Threading.Tasks.Dataflow.ISourceBlock<TOutput> source, TimeSpan timeout, System.Threading.CancellationToken cancellationToken);
static member ReceiveAsync : System.Threading.Tasks.Dataflow.ISourceBlock<'Output> * TimeSpan * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Output>
<Extension()>
Public Function ReceiveAsync(Of TOutput) (source As ISourceBlock(Of TOutput), timeout As TimeSpan, cancellationToken As CancellationToken) As Task(Of TOutput)
类型参数
- TOutput
源中包含的数据的类型。The type of data contained in the source.
参数
- source
- ISourceBlock<TOutput>
从中接收值的源。The source from which to receive the value.
- timeout
- TimeSpan
等待同步操作完成的最大时间间隔(以毫秒为单位),或表示 -1 毫秒无限期等待的时间间隔。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.
返回
- Task<TOutput>
表示异步接收操作的任务。A task that represents the asynchronous receive operation. 当从源成功检索出值时,则返回项的任务将完成,并且其 Result 将返回接值。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. 如果因为源为空且已完成而无法检索值,则返回任务中会引发 InvalidOperationException 异常。If the value cannot be retrieved because the source is empty and completed, an InvalidOperationException exception is thrown in the returned task.
例外
source 为 null。source is null.
timeout 是一个非 -1 毫秒的负数,而 -1 表示无限期超时期限。timeout is a negative number other than -1 milliseconds, which represents an infinite time-out period.
- 或 --or-
timeout 大于 MaxValue。timeout is greater than MaxValue.