create_task Function
Creates a PPL task object. create_task can be used anywhere you would have used a task constructor. It is provided mainly for convenience, because it allows use of the auto keyword while creating tasks.
template<
typename _Ty
>
auto create_task(
_Ty_Param
) -> task<typename details::_TaskTypeFromParam<_Ty>::_Type>;
template<
typename _Ty
>
auto create_task(
_Ty_Param,
cancellation_token _Token
) -> task<typename details::_TaskTypeFromParam<_Ty>::_Type>;
Parameters
_Ty
The type of the parameter from which the task is to be constructed._Param
The parameter from which the task is to be constructed. This could be a lambda or function object, a task_completion_event object, a different task object, or a Windows::Foundation::IAsyncInfo interface if you are using tasks in your Windows Store app._Token
The cancellation token to associate with the task. When the source for this token is canceled, cancellation will be requested on the task.
Return Value
A new task of type T, that is inferred from _Param.
Remarks
For more detailed info, including examples, see Task Parallelism (Concurrency Runtime).
The first overload behaves like a task constructor that takes a single parameter.
The second overload associates the cancellation token provided with the newly created task. If you use this overload you are not allowed to pass in a different task object as the first parameter.
The type of the returned task is inferred from the first parameter to the function. If _Param is a task_completion_event<T>, a task<T>, or a functor that returns either type T or task<T>, the type of the created task is task<T>.
In a Windows Store app, if _Param is of type Windows::Foundation::IAsyncOperation<TResult>^ or Windows::Foundation::IAsyncOperationWithProgress<TResult,TProgress>^, or a functor that returns either of those types, the created task will be of type task<T>. If _Param is of type Windows::Foundation::IAsyncAction^ or Windows::Foundation::IAsyncActionWithProgress<TProgress>^, or a functor that returns either of those types, the created task will have type task<void>.
Although the create_task function and the task constructor do not throw, it is important to understand how exception handling works when you retrieve a task’s result. For more info, see Tasks and Continuations.
Requirements
Header: ppltasks.h
Namespace: concurrency