Task<TResult> Task<TResult> Task<TResult> Task<TResult> Class

Definition

Represents an asynchronous operation that can return a value.

generic <typename TResult>
public ref class Task : System::Threading::Tasks::Task
public class Task<TResult> : System.Threading.Tasks.Task
type Task<'Result> = class
    inherit Task
Public Class Task(Of TResult)
Inherits Task

Type Parameters

TResult

The type of the result produced by this Task<TResult>.

Inheritance
Task<TResult>Task<TResult>Task<TResult>Task<TResult>

Remarks

The Task<TResult> class represents a single operation that returns a value and that usually executes asynchronously. Task<TResult> objects are one of the central components of the task-based asynchronous pattern first introduced in the .NET Framework 4. Because the work performed by a Task<TResult> object typically executes asynchronously on a thread pool thread rather than synchronously on the main application thread, you can use the Status property, as well as the IsCanceled, IsCompleted, and IsFaulted properties, to determine the state of a task. Most commonly, a lambda expression is used to specify the work that the task is to perform.

Task<TResult> instances may be created in a variety of ways. The most common approach, which is available starting with the .NET Framework 4.5, is to call the static Task.Run<TResult>(Func<TResult>) or Task.Run<TResult>(Func<TResult>, CancellationToken) method. These methods provide a simple way to start a task by using default values and without acquiring additional parameters. The following example uses the Task.Run<TResult>(Func<TResult>) method to start a task that loops and then displays the number of loop iterations:

using System;
using System.Threading.Tasks;

public class Example
{
   public static void Main()
   {
      var t = Task<int>.Run( () => {
                                      // Just loop.
                                      int max = 1000000;
                                      int ctr = 0;
                                      for (ctr = 0; ctr <= max; ctr++) {
                                         if (ctr == max / 2 && DateTime.Now.Hour <= 12) {
                                            ctr++;
                                            break;
                                         }
                                      }
                                      return ctr;
                                    } );
      Console.WriteLine("Finished {0:N0} iterations.", t.Result);
   }
}
// The example displays output like the following:
//        Finished 1,000,001 loop iterations.
Imports System.Threading.Tasks

Module Example
   Public Sub Main()
      Dim t As Task(Of Integer) = Task.Run(Function()
                                  Dim max As Integer = 1000000
                                  Dim ctr As Integer
                                  For ctr = 0 to max
                                     If ctr = max \ 2 And Date.Now.Hour <= 12 Then
                                        ctr += 1
                                        Exit For
                                     End If
                                  Next
                                  Return ctr
                               End Function)
      Console.WriteLine("Finished {0:N0} iterations.", t.Result)
   End Sub
End Module
' The example displays the following output:
'       Finished 1,000,001 loop iterations

An alternative, and the most common way to start a task in the .NET Framework 4, is to call the static TaskFactory.StartNew or TaskFactory<TResult>.StartNew method. The Task.Factory property returns a TaskFactory object, and the Task<TResult>.Factory property returns a TaskFactory<TResult> object. Overloads of their StartNew method let you pass arguments, define task creation options, and specify a task scheduler. The following example uses the TaskFactory<TResult>.StartNew(Func<TResult>) method to start a task. It is functionally equivalent to the code in the previous example.

using System;
using System.Threading.Tasks;

public class Example
{
   public static void Main()
   {
      var t = Task<int>.Factory.StartNew( () => {
                                      // Just loop.
                                      int max = 1000000;
                                      int ctr = 0;
                                      for (ctr = 0; ctr <= max; ctr++) {
                                         if (ctr == max / 2 && DateTime.Now.Hour <= 12) {
                                            ctr++;
                                            break;
                                         }
                                      }
                                      return ctr;
                               } );
      Console.WriteLine("Finished {0:N0} iterations.", t.Result);
   }
}
// The example displays the following output:
//        Finished 1000001 loop iterations
Imports System.Threading.Tasks

Module Example
   Public Sub Main()
      Dim t = Task(Of Integer).Factory.StartNew(Function()
                                  Dim max As Integer = 1000000
                                  Dim ctr As Integer
                                  For ctr = 0 to max
                                     If ctr = max \ 2 And Date.Now.Hour <= 12 Then
                                       ctr += 1
                                       Exit For
                                     End If
                                  Next
                                  Return ctr
                               End Function)
      Console.WriteLine("Finished {0:N0} iterations.", t.Result)
   End Sub
End Module
' The example displays output like the following:
'       Finished 1,000,001 iterations

For more complete examples, see Task-based Asynchronous Programming.

The Task<TResult> class also provides constructors that initialize the task but that do not schedule it for execution. For performance reasons, the Task.Run and Task.Factory.StartNew methods are the preferred mechanisms for creating and scheduling computational tasks, but for scenarios where task creation and scheduling must be separated, the constructors may be used, and the task's Start method may then be used to schedule the task for execution at a later time.

Starting with desktop apps that target the .NET Framework 4.6, the culture of the thread that creates and invokes a task becomes part of the thread's context. That is, regardless of the current culture of the thread on which the task executes, the current culture of the task is the culture of the calling thread. For apps that target versions of the .NET Framework prior to the .NET Framework 4.6, the culture of the task is the culture of the thread on which the task executes. For more information, see the "Culture and task-based asynchronous operations" section in the CultureInfo topic. Note that Store apps follow the Windows Runtime in setting and getting the default culture.

For operations that do not return a value, you use the Task class. If you're developing with C# 7, for a more lightweight task that is a value type rather than a reference type, use the System.Threading.Tasks.ValueTask<TResult> structure; it is supported starting with C# 7.

Constructors

Task<TResult>(Func<Object,TResult>, Object) Task<TResult>(Func<Object,TResult>, Object) Task<TResult>(Func<Object,TResult>, Object) Task<TResult>(Func<Object,TResult>, Object)

Initializes a new Task<TResult> with the specified function and state.

Task<TResult>(Func<Object,TResult>, Object, CancellationToken) Task<TResult>(Func<Object,TResult>, Object, CancellationToken) Task<TResult>(Func<Object,TResult>, Object, CancellationToken) Task<TResult>(Func<Object,TResult>, Object, CancellationToken)

Initializes a new Task<TResult> with the specified action, state, and options.

Task<TResult>(Func<Object,TResult>, Object, CancellationToken, TaskCreationOptions) Task<TResult>(Func<Object,TResult>, Object, CancellationToken, TaskCreationOptions) Task<TResult>(Func<Object,TResult>, Object, CancellationToken, TaskCreationOptions) Task<TResult>(Func<Object,TResult>, Object, CancellationToken, TaskCreationOptions)

Initializes a new Task<TResult> with the specified action, state, and options.

Task<TResult>(Func<Object,TResult>, Object, TaskCreationOptions) Task<TResult>(Func<Object,TResult>, Object, TaskCreationOptions) Task<TResult>(Func<Object,TResult>, Object, TaskCreationOptions) Task<TResult>(Func<Object,TResult>, Object, TaskCreationOptions)

Initializes a new Task<TResult> with the specified action, state, and options.

Task<TResult>(Func<TResult>) Task<TResult>(Func<TResult>) Task<TResult>(Func<TResult>) Task<TResult>(Func<TResult>)

Initializes a new Task<TResult> with the specified function.

Task<TResult>(Func<TResult>, CancellationToken) Task<TResult>(Func<TResult>, CancellationToken) Task<TResult>(Func<TResult>, CancellationToken) Task<TResult>(Func<TResult>, CancellationToken)

Initializes a new Task<TResult> with the specified function.

Task<TResult>(Func<TResult>, CancellationToken, TaskCreationOptions) Task<TResult>(Func<TResult>, CancellationToken, TaskCreationOptions) Task<TResult>(Func<TResult>, CancellationToken, TaskCreationOptions) Task<TResult>(Func<TResult>, CancellationToken, TaskCreationOptions)

Initializes a new Task<TResult> with the specified function and creation options.

Task<TResult>(Func<TResult>, TaskCreationOptions) Task<TResult>(Func<TResult>, TaskCreationOptions) Task<TResult>(Func<TResult>, TaskCreationOptions) Task<TResult>(Func<TResult>, TaskCreationOptions)

Initializes a new Task<TResult> with the specified function and creation options.

Properties

AsyncState AsyncState AsyncState AsyncState

Gets the state object supplied when the Task was created, or null if none was supplied.

(Inherited from Task)
CreationOptions CreationOptions CreationOptions CreationOptions

Gets the TaskCreationOptions used to create this task.

(Inherited from Task)
Exception Exception Exception Exception

Gets the AggregateException that caused the Task to end prematurely. If the Task completed successfully or has not yet thrown any exceptions, this will return null.

(Inherited from Task)
Factory Factory Factory Factory

Provides access to factory methods for creating and configuring Task<TResult> instances.

IAsyncResult.AsyncWaitHandle IAsyncResult.AsyncWaitHandle IAsyncResult.AsyncWaitHandle IAsyncResult.AsyncWaitHandle

Gets a WaitHandle that can be used to wait for the task to complete.

(Inherited from Task)
IAsyncResult.CompletedSynchronously IAsyncResult.CompletedSynchronously IAsyncResult.CompletedSynchronously IAsyncResult.CompletedSynchronously

Gets an indication of whether the operation completed synchronously.

(Inherited from Task)
Id Id Id Id

Gets an ID for this Task instance.

(Inherited from Task)
IsCanceled IsCanceled IsCanceled IsCanceled

Gets whether this Task instance has completed execution due to being canceled.

(Inherited from Task)
IsCompleted IsCompleted IsCompleted IsCompleted

Gets whether this Task has completed.

(Inherited from Task)
IsCompletedSuccessfully IsCompletedSuccessfully IsCompletedSuccessfully IsCompletedSuccessfully Inherited from Task
IsFaulted IsFaulted IsFaulted IsFaulted

Gets whether the Task completed due to an unhandled exception.

(Inherited from Task)
Result Result Result Result

Gets the result value of this Task<TResult>.

Status Status Status Status

Gets the TaskStatus of this task.

(Inherited from Task)

Methods

ConfigureAwait(Boolean) ConfigureAwait(Boolean) ConfigureAwait(Boolean) ConfigureAwait(Boolean)

Configures an awaiter used to await this Task<TResult>.

ContinueWith(Action<Task,Object>, Object) ContinueWith(Action<Task,Object>, Object) ContinueWith(Action<Task,Object>, Object) ContinueWith(Action<Task,Object>, Object)

Creates a continuation that receives caller-supplied state information and executes when the target Task completes.

(Inherited from Task)
ContinueWith(Action<Task,Object>, Object, CancellationToken) ContinueWith(Action<Task,Object>, Object, CancellationToken) ContinueWith(Action<Task,Object>, Object, CancellationToken) ContinueWith(Action<Task,Object>, Object, CancellationToken)

Creates a continuation that receives caller-supplied state information and a cancellation token and that executes asynchronously when the target Task completes.

(Inherited from Task)
ContinueWith(Action<Task,Object>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task,Object>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task,Object>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task,Object>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler)

Creates a continuation that receives caller-supplied state information and a cancellation token and that executes when the target Task completes. The continuation executes based on a set of specified conditions and uses a specified scheduler.

(Inherited from Task)
ContinueWith(Action<Task,Object>, Object, TaskContinuationOptions) ContinueWith(Action<Task,Object>, Object, TaskContinuationOptions) ContinueWith(Action<Task,Object>, Object, TaskContinuationOptions) ContinueWith(Action<Task,Object>, Object, TaskContinuationOptions)

Creates a continuation that receives caller-supplied state information and executes when the target Task completes. The continuation executes based on a set of specified conditions.

(Inherited from Task)
ContinueWith(Action<Task,Object>, Object, TaskScheduler) ContinueWith(Action<Task,Object>, Object, TaskScheduler) ContinueWith(Action<Task,Object>, Object, TaskScheduler) ContinueWith(Action<Task,Object>, Object, TaskScheduler)

Creates a continuation that receives caller-supplied state information and executes asynchronously when the target Task completes. The continuation uses a specified scheduler.

(Inherited from Task)
ContinueWith(Action<Task<TResult>,Object>, Object) ContinueWith(Action<Task<TResult>,Object>, Object) ContinueWith(Action<Task<TResult>,Object>, Object) ContinueWith(Action<Task<TResult>,Object>, Object)

Creates a continuation that that is passed state information and that executes when the target Task<TResult> completes.

ContinueWith(Action<Task<TResult>,Object>, Object, CancellationToken) ContinueWith(Action<Task<TResult>,Object>, Object, CancellationToken) ContinueWith(Action<Task<TResult>,Object>, Object, CancellationToken) ContinueWith(Action<Task<TResult>,Object>, Object, CancellationToken)

Creates a continuation that executes when the target Task<TResult> completes.

ContinueWith(Action<Task<TResult>,Object>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task<TResult>,Object>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task<TResult>,Object>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task<TResult>,Object>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler)

Creates a continuation that executes when the target Task<TResult> completes.

ContinueWith(Action<Task<TResult>,Object>, Object, TaskContinuationOptions) ContinueWith(Action<Task<TResult>,Object>, Object, TaskContinuationOptions) ContinueWith(Action<Task<TResult>,Object>, Object, TaskContinuationOptions) ContinueWith(Action<Task<TResult>,Object>, Object, TaskContinuationOptions)

Creates a continuation that executes when the target Task<TResult> completes.

ContinueWith(Action<Task<TResult>,Object>, Object, TaskScheduler) ContinueWith(Action<Task<TResult>,Object>, Object, TaskScheduler) ContinueWith(Action<Task<TResult>,Object>, Object, TaskScheduler) ContinueWith(Action<Task<TResult>,Object>, Object, TaskScheduler)

Creates a continuation that executes when the target Task<TResult> completes.

ContinueWith(Action<Task<TResult>>) ContinueWith(Action<Task<TResult>>) ContinueWith(Action<Task<TResult>>) ContinueWith(Action<Task<TResult>>)

Creates a continuation that executes asynchronously when the target task completes.

ContinueWith(Action<Task<TResult>>, CancellationToken) ContinueWith(Action<Task<TResult>>, CancellationToken) ContinueWith(Action<Task<TResult>>, CancellationToken) ContinueWith(Action<Task<TResult>>, CancellationToken)

Creates a cancelable continuation that executes asynchronously when the target Task<TResult> completes.

ContinueWith(Action<Task<TResult>>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task<TResult>>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task<TResult>>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task<TResult>>, CancellationToken, TaskContinuationOptions, TaskScheduler)

Creates a continuation that executes according the condition specified in continuationOptions.

ContinueWith(Action<Task<TResult>>, TaskContinuationOptions) ContinueWith(Action<Task<TResult>>, TaskContinuationOptions) ContinueWith(Action<Task<TResult>>, TaskContinuationOptions) ContinueWith(Action<Task<TResult>>, TaskContinuationOptions)

Creates a continuation that executes according the condition specified in continuationOptions.

ContinueWith(Action<Task<TResult>>, TaskScheduler) ContinueWith(Action<Task<TResult>>, TaskScheduler) ContinueWith(Action<Task<TResult>>, TaskScheduler) ContinueWith(Action<Task<TResult>>, TaskScheduler)

Creates a continuation that executes asynchronously when the target Task<TResult> completes.

ContinueWith(Action<Task>) ContinueWith(Action<Task>) ContinueWith(Action<Task>) ContinueWith(Action<Task>)

Creates a continuation that executes asynchronously when the target Task completes.

(Inherited from Task)
ContinueWith(Action<Task>, CancellationToken) ContinueWith(Action<Task>, CancellationToken) ContinueWith(Action<Task>, CancellationToken) ContinueWith(Action<Task>, CancellationToken)

Creates a continuation that receives a cancellation token and executes asynchronously when the target Task completes.

(Inherited from Task)
ContinueWith(Action<Task>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith(Action<Task>, CancellationToken, TaskContinuationOptions, TaskScheduler)

Creates a continuation that executes when the target task competes according to the specified TaskContinuationOptions. The continuation receives a cancellation token and uses a specified scheduler.

(Inherited from Task)
ContinueWith(Action<Task>, TaskContinuationOptions) ContinueWith(Action<Task>, TaskContinuationOptions) ContinueWith(Action<Task>, TaskContinuationOptions) ContinueWith(Action<Task>, TaskContinuationOptions)

Creates a continuation that executes when the target task completes according to the specified TaskContinuationOptions.

(Inherited from Task)
ContinueWith(Action<Task>, TaskScheduler) ContinueWith(Action<Task>, TaskScheduler) ContinueWith(Action<Task>, TaskScheduler) ContinueWith(Action<Task>, TaskScheduler)

Creates a continuation that executes asynchronously when the target Task completes. The continuation uses a specified scheduler.

(Inherited from Task)
ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object)

Creates a continuation that executes when the target Task<TResult> completes.

ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, CancellationToken) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, CancellationToken) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, CancellationToken) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, CancellationToken)

Creates a continuation that executes when the target Task<TResult> completes.

ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler)

Creates a continuation that executes when the target Task<TResult> completes.

ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, TaskContinuationOptions) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, TaskContinuationOptions) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, TaskContinuationOptions) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, TaskContinuationOptions)

Creates a continuation that executes when the target Task<TResult> completes.

ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,Object,TNewResult>, Object, TaskScheduler)

Creates a continuation that executes when the target Task<TResult> completes.

ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>)

Creates a continuation that executes asynchronously when the target Task<TResult> completes.

ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, CancellationToken) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, CancellationToken) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, CancellationToken) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, CancellationToken)

Creates a continuation that executes asynchronously when the target Task<TResult> completes.

ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, CancellationToken, TaskContinuationOptions, TaskScheduler)

Creates a continuation that executes according the condition specified in continuationOptions.

ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, TaskContinuationOptions) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, TaskContinuationOptions) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, TaskContinuationOptions) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, TaskContinuationOptions)

Creates a continuation that executes according the condition specified in continuationOptions.

ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, TaskScheduler) ContinueWith<TNewResult>(Func<Task<TResult>,TNewResult>, TaskScheduler)

Creates a continuation that executes asynchronously when the target Task<TResult> completes.

ContinueWith<TResult>(Func<Task,Object,TResult>, Object) ContinueWith<TResult>(Func<Task,Object,TResult>, Object) ContinueWith<TResult>(Func<Task,Object,TResult>, Object) ContinueWith<TResult>(Func<Task,Object,TResult>, Object)

Creates a continuation that receives caller-supplied state information and executes asynchronously when the target Task completes and returns a value.

(Inherited from Task)
ContinueWith<TResult>(Func<Task,Object,TResult>, Object, CancellationToken) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, CancellationToken) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, CancellationToken) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, CancellationToken)

Creates a continuation that executes asynchronously when the target Task completes and returns a value. The continuation receives caller-supplied state information and a cancellation token.

(Inherited from Task)
ContinueWith<TResult>(Func<Task,Object,TResult>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler)

Creates a continuation that executes based on the specified task continuation options when the target Task completes and returns a value. The continuation receives caller-supplied state information and a cancellation token and uses the specified scheduler.

(Inherited from Task)
ContinueWith<TResult>(Func<Task,Object,TResult>, Object, TaskContinuationOptions) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, TaskContinuationOptions) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, TaskContinuationOptions) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, TaskContinuationOptions)

Creates a continuation that executes based on the specified task continuation options when the target Task completes. The continuation receives caller-supplied state information.

(Inherited from Task)
ContinueWith<TResult>(Func<Task,Object,TResult>, Object, TaskScheduler) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, TaskScheduler) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, TaskScheduler) ContinueWith<TResult>(Func<Task,Object,TResult>, Object, TaskScheduler)

Creates a continuation that executes asynchronously when the target Task completes. The continuation receives caller-supplied state information and uses a specified scheduler.

(Inherited from Task)
ContinueWith<TResult>(Func<Task,TResult>) ContinueWith<TResult>(Func<Task,TResult>) ContinueWith<TResult>(Func<Task,TResult>) ContinueWith<TResult>(Func<Task,TResult>)

Creates a continuation that executes asynchronously when the target Task<TResult> completes and returns a value.

(Inherited from Task)
ContinueWith<TResult>(Func<Task,TResult>, CancellationToken) ContinueWith<TResult>(Func<Task,TResult>, CancellationToken) ContinueWith<TResult>(Func<Task,TResult>, CancellationToken) ContinueWith<TResult>(Func<Task,TResult>, CancellationToken)

Creates a continuation that executes asynchronously when the target Task completes and returns a value. The continuation receives a cancellation token.

(Inherited from Task)
ContinueWith<TResult>(Func<Task,TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TResult>(Func<Task,TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TResult>(Func<Task,TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler) ContinueWith<TResult>(Func<Task,TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler)

Creates a continuation that executes according to the specified continuation options and returns a value. The continuation is passed a cancellation token and uses a specified scheduler.

(Inherited from Task)
ContinueWith<TResult>(Func<Task,TResult>, TaskContinuationOptions) ContinueWith<TResult>(Func<Task,TResult>, TaskContinuationOptions) ContinueWith<TResult>(Func<Task,TResult>, TaskContinuationOptions) ContinueWith<TResult>(Func<Task,TResult>, TaskContinuationOptions)

Creates a continuation that executes according to the specified continuation options and returns a value.

(Inherited from Task)
ContinueWith<TResult>(Func<Task,TResult>, TaskScheduler) ContinueWith<TResult>(Func<Task,TResult>, TaskScheduler) ContinueWith<TResult>(Func<Task,TResult>, TaskScheduler) ContinueWith<TResult>(Func<Task,TResult>, TaskScheduler)

Creates a continuation that executes asynchronously when the target Task completes and returns a value. The continuation uses a specified scheduler.

(Inherited from Task)
Dispose() Dispose() Dispose() Dispose()

Releases all resources used by the current instance of the Task class.

(Inherited from Task)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

Disposes the Task, releasing all of its unmanaged resources.

(Inherited from Task)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetAwaiter() GetAwaiter() GetAwaiter() GetAwaiter()

Gets an awaiter used to await this Task<TResult>.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
RunSynchronously() RunSynchronously() RunSynchronously() RunSynchronously()

Runs the Task synchronously on the current TaskScheduler.

(Inherited from Task)
RunSynchronously(TaskScheduler) RunSynchronously(TaskScheduler) RunSynchronously(TaskScheduler) RunSynchronously(TaskScheduler)

Runs the Task synchronously on the TaskScheduler provided.

(Inherited from Task)
Start() Start() Start() Start()

Starts the Task, scheduling it for execution to the current TaskScheduler.

(Inherited from Task)
Start(TaskScheduler) Start(TaskScheduler) Start(TaskScheduler) Start(TaskScheduler)

Starts the Task, scheduling it for execution to the specified TaskScheduler.

(Inherited from Task)
ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)
Wait() Wait() Wait() Wait()

Waits for the Task to complete execution.

(Inherited from Task)
Wait(CancellationToken) Wait(CancellationToken) Wait(CancellationToken) Wait(CancellationToken)

Waits for the Task to complete execution. The wait terminates if a cancellation token is canceled before the task completes.

(Inherited from Task)
Wait(Int32) Wait(Int32) Wait(Int32) Wait(Int32)

Waits for the Task to complete execution within a specified number of milliseconds.

(Inherited from Task)
Wait(Int32, CancellationToken) Wait(Int32, CancellationToken) Wait(Int32, CancellationToken) Wait(Int32, CancellationToken)

Waits for the Task to complete execution. The wait terminates if a timeout interval elapses or a cancellation token is canceled before the task completes.

(Inherited from Task)
Wait(TimeSpan) Wait(TimeSpan) Wait(TimeSpan) Wait(TimeSpan)

Waits for the Task to complete execution within a specified time interval.

(Inherited from Task)

Extension Methods

Unwrap(Task<Task>) Unwrap(Task<Task>) Unwrap(Task<Task>) Unwrap(Task<Task>)

Creates a proxy Task that represents the asynchronous operation of a TryExecuteTaskInline(Task, Boolean).

Unwrap<TResult>(Task<Task<TResult>>) Unwrap<TResult>(Task<Task<TResult>>) Unwrap<TResult>(Task<Task<TResult>>) Unwrap<TResult>(Task<Task<TResult>>)

Creates a proxy Task that represents the asynchronous operation of a Task<Task<T>> (C#) or Task (Of Task(Of T)) (Visual Basic).

DispatcherOperationWait(Task) DispatcherOperationWait(Task) DispatcherOperationWait(Task) DispatcherOperationWait(Task)

Waits indefinitely for the underlying DispatcherOperation to complete.

DispatcherOperationWait(Task, TimeSpan) DispatcherOperationWait(Task, TimeSpan) DispatcherOperationWait(Task, TimeSpan) DispatcherOperationWait(Task, TimeSpan)

Waits for the specified amount of time for the underlying DispatcherOperation to complete.

IsDispatcherOperationTask(Task) IsDispatcherOperationTask(Task) IsDispatcherOperationTask(Task) IsDispatcherOperationTask(Task)

Returns a value that indicates whether this Task is associated with a DispatcherOperation.

Applies to

Thread Safety

All members of Task<TResult>, except for Dispose(), are thread-safe and may be used from multiple threads concurrently.

See also