Task.Run<TResult> Method (Func<TResult>, CancellationToken)
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Queues the specified work to run on the ThreadPool and returns a Task(TResult) handle for that work.
Assembly: mscorlib (in mscorlib.dll)
public static Task<TResult> Run<TResult>( Func<TResult> function, CancellationToken cancellationToken )
Type Parameters
- TResult
The result type of the task.
Parameters
- function
- Type: System.Func<TResult>
The work to execute asynchronously
- cancellationToken
- Type: System.Threading.CancellationToken
A cancellation token that should be used to cancel the work
Return Value
Type: System.Threading.Tasks.Task<TResult>A Task(TResult) that represents the work queued to execute in the ThreadPool.
| Exception | Condition |
|---|---|
| ArgumentNullException | The function parameter was null. |
| ObjectDisposedException | The CancellationTokenSource associated with cancellationToken was disposed. |
Show: