AsyncInfo::Run<TResult> Method (Func<CancellationToken, Task<TResult>>)
Creates and starts a Windows Runtime asynchronous operation by using a function that generates a started task that returns results. The task can support cancellation.
Namespace: System.Runtime.InteropServices.WindowsRuntime
Assembly: System.Runtime.WindowsRuntime (in System.Runtime.WindowsRuntime.dll)
public: generic<typename TResult> static IAsyncOperation<TResult>^ Run( Func<CancellationToken, Task<TResult>^>^ taskProvider )
Type Parameters
- TResult
The type that returns the result.
Parameters
- taskProvider
- Type: System::Func<CancellationToken, Task<TResult>>
A delegate that represents the function that creates and starts the task. The started task is represented by the Windows Runtime asynchronous operation that is returned. The function is passed a cancellation token that the task can monitor to be notified of cancellation requests; you can ignore the token if your task does not support cancellation.
Return Value
Type: IAsyncOperation<TResult>A started Windows.Foundation.IAsyncOperation<TResult> instance that represents the task that is generated by taskProvider.
| Exception | Condition |
|---|---|
| ArgumentNullException | taskProvider is nullptr. |
| InvalidOperationException | taskProvider returns an unstarted task. |
This method passes a cancellation token to the function that is specified by taskProvider. This token provides a connection between Windows Runtime cancellation and .NET Framework task cancellation; if the action is canceled, the task is canceled. If your task does not support cancellation, ignore the token.