System::Threading::Tasks::Task class

Task class

Represents an asynchronous operation that can be awaited and composed with other tasks.

class Task : public System::IDisposable

Methods

MethodDescription
Activate(const SharedPtr<TaskScheduler>&)Activates the task for execution on a scheduler.
AddCompletionAction(const Action<>&)Adds a continuation action to be executed upon completion.
Cancel()Marks the task as cancelled and finishes task.
Complete()Marks the task as completed and finishes task.
ConfigureAwait(bool) constConfigures how awaits on this task should behave regarding context capture.
ContinueWith(const Action<TaskPtr>&)Creates a continuation that executes when the task completes.
ContinueWith(const Func<TaskPtr, TResult>&)Creates a continuation that executes when the task completes.
Dispose() overrideReleases resources associated with the task.
Execute()Executes the task’s function.
get_AsyncState() constGets the user-defined state object associated with the task.
static get_CompletedTask()Gets a completed task (singleton)
static get_CurrentId()
get_Exception() constGets the ID for task.
get_Id() const
get_IsCanceled() constGets whether the task completed due to cancellation.
get_IsCompleted() constGets whether the task has completed.
get_IsFaulted() constGets whether the task completed due to an unhandled exception.
get_Scheduler() constGets the scheduler associated with this task.
get_Status() constGets the current status of the task.
GetAwaiter() constGets an awaiter for this task for use with Await.
RunSynchronously()Runs the task synchronously on the current thread.
RunSynchronously(const SharedPtr<TaskScheduler>&)Runs the task synchronously using the specified scheduler.
set_Function(const FunctionT&)Sets the internal function to execute.
set_Scheduler(const SharedPtr<TaskScheduler>&)Sets the scheduler associated with this task.
set_Status(TaskStatus)Sets the task status.
Start()Starts the task execution using the default scheduler.
Start(const SharedPtr<TaskScheduler>&)Starts the task execution using the specified scheduler.
Task(const Action<>&)Constructs a Task with an action to execute.
Task(const Action<>&, const CancellationToken&)Constructs a Task with an action and cancellation token.
Task(const Action<SharedPtr<Object>>&, const SharedPtr<Object>&)Constructs a Task with a stateful action and state object.
Task(const Action<SharedPtr<Object>>&, const SharedPtr<Object>&, const CancellationToken&)Constructs a Task with stateful action, state, and cancellation token.
Task()Internal constructor for creating uninitialized tasks.
Wait(const CancellationToken&)Waits for the task to complete with cancellation support.
Wait()Waits for the task to complete.
~Task()Destructor.

Typedefs

TypedefDescription
FunctionTInternal implementation. Not for user code.

Remarks

Provides a C++ implementation similar to System.Threading.Tasks.Task in .NET, supporting cancellation, continuations, and async/await patterns

See Also