Windows apps
Collapse the table of content
Expand the table of content

task_completion_event Class

 

For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

The task_completion_event class allows you to delay the execution of a task until a condition is satisfied, or start a task in response to an external event.

template<typename _ResultType>
class task_completion_event;

template<>
class task_completion_event<void>;

Parameters

_ResultType
The result type of this task_completion_event class.

T

Public Constructors

NameDescription
task_completion_event::task_completion_event ConstructorConstructs a task_completion_event object.

Public Methods

NameDescription
task_completion_event::set MethodOverloaded. Sets the task completion event.
task_completion_event::set_exception MethodOverloaded. Propagates an exception to all tasks associated with this event.

Use a task created from a task completion event when your scenario requires you to create a task that will complete, and thereby have its continuations scheduled for execution, at some point in the future. The task_completion_event must have the same type as the task you create, and calling the set method on the task completion event with a value of that type will cause the associated task to complete, and provide that value as a result to its continuations.

If the task completion event is never signaled, any tasks created from it will be canceled when it is destructed.

task_completion_event behaves like a smart pointer, and should be passed by value.

task_completion_event

Header: ppltasks.h

Namespace: concurrency

Sets the task completion event.

bool set(_ResultType _Result) const ;

bool set() const ;

Parameters

_Result
The result to set this event with.

Return Value

The method returns true if it was successful in setting the event. It returns false if the event is already set.

Remarks

In the presence of multiple or concurrent calls to set, only the first call will succeed and its result (if any) will be stored in the task completion event. The remaining sets are ignored and the method will return false. When you set a task completion event, all the tasks created from that event will immediately complete, and its continuations, if any, will be scheduled. Task completion objects that have a _ResultType other than void will pass the value to their continuations.

Propagates an exception to all tasks associated with this event.

template<typename _E>
__declspec(noinline) bool set_exception(_E _Except) const;

__declspec(noinline) bool set_exception(std::exception_ptr _ExceptionPtr) const ;

Parameters

_E
_Except
_ExceptionPtr

Return Value

Constructs a task_completion_event object.

task_completion_event();

concurrency Namespace

Show:
© 2017 Microsoft