task::then Method

Adds a continuation task to this task.

template<
   typename _Function
>
auto then(
   const _Function& _Func
) const -> typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_TaskOfType;

template<
   typename _Function
>
auto then(
   const _Function& _Func,
   cancellation_token _CancellationToken
) const -> typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_TaskOfType;

template<
   typename _Function
>
auto then(
   const _Function& _Func,
   task_continuation_context _ContinuationContext
) const -> typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_TaskOfType;

template<
   typename _Function
>
auto then(
   const _Function& _Func,
   cancellation_token _CancellationToken,
   task_continuation_context _ContinuationContext
) const -> typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_TaskOfType;

template<
   typename _Function
>
auto then(
   const _Function& _Func
) const -> typename details::_ContinuationTypeTraits<_Function, void>::_TaskOfType;

template<
   typename _Function
>
auto then(
   const _Function& _Func,
   cancellation_token _CancellationToken
) const -> typename details::_ContinuationTypeTraits<_Function, void>::_TaskOfType;

template<
   typename _Function
>
auto then(
   const _Function& _Func,
   task_continuation_context _ContinuationContext
) const -> typename details::_ContinuationTypeTraits<_Function, void>::_TaskOfType;

template<
   typename _Function
>
auto then(
   const _Function& _Func,
   cancellation_token _CancellationToken,
   task_continuation_context _ContinuationContext
) const -> typename details::_ContinuationTypeTraits<_Function, void>::_TaskOfType;

Parameters

  • _Function
    The type of the function object that will be invoked by this task.

  • _Func
    The continuation function to execute when this task completes. This continuation function must take as input a variable of either result_type or task<result_type>, where result_type is the type of the result this task produces.

  • _CancellationToken
    The cancellation token to associate with the continuation task. A continuation task that is created without a cancellation token will inherit the token of its antecedent task.

  • _ContinuationContext
    A variable that specifies where the continuation should execute. This variable is only useful when used in a Windows Store app. For more information, see task_continuation_context

Return Value

The newly created continuation task. The result type of the returned task is determined by what _Func returns.

Remarks

A continuation task (also known just as a continuation) is an asynchronous task that is invoked by another task, which is known as the antecedent, when the antecedent completes. For more information about continuations and how to use them to compose asynchronous work, see Continuation Tasks in the document Task Parallelism (Concurrency Runtime).

The overloads of then that take a lambda or functor that return Windows::Foundation::IAsyncInfo are only available to Windows Store apps.

Requirements

Header: ppltasks.h

Namespace: concurrency

See Also

Reference

task Class (Concurrency Runtime)