Constructs a task object.
task(); template< typename _Ty > explicit task( _Ty_Param ); template< typename _Ty > explicit task( _Ty_Param, cancellation_token _Token ); task( const task& _Other ); task( task&& _Other );
The default constructor for a task is only present in order to allow tasks to be used within containers. A default constructed task cannot be used until you assign a valid task to it. Methods such as get, wait or then will throw an invalid_argument exception when called on a default constructed task.
A task that is created from a task_completion_event will complete (and have its continuations scheduled) when the task completion event is set.
The version of the constructor that takes a cancellation token creates a task that can be canceled using the cancellation_token_source the token was obtained from. Tasks created without a cancellation token are not cancelable.
Tasks created from a Windows::Foundation::IAsyncInfo interface or a lambda that returns an IAsyncInfo interface reach their terminal state when the enclosed Windows Runtime asynchronous operation or action completes. Similarly, tasks created from a lamda that returns a task<result_type> reach their terminal state when the inner task reaches its terminal state, and not when the lamda returns.
task behaves like a smart pointer and is safe to pass around by value. It can be accessed by multiple threads without the need for locks.
The constructor overloads that take a Windows::Foundation::IAsyncInfo interface or a lambda returning such an interface, are only available to Metro style apps.
For more information, see Task Parallelism (Concurrency Runtime).