task::then 方法 (C++ REST SDK)
向此任务添加延续任务。
template<
typename _Function
>
__declspec(
noinline
) auto then(const _Function& _Func) const -> typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_TaskOfType;
template<
typename _Function
>
__declspec(
noinline
) auto then(const _Function& _Func, const task_options& _TaskOptions) const -> typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_TaskOfType;
template<
typename _Function
>
__declspec(
noinline
) auto then(const _Function& _Func, cancellation_token _CancellationToken, task_continuation_context _ContinuationContext) const -> typename details::_ContinuationTypeTraits<_Function, _ReturnType>::_TaskOfType;
template<
typename _Function
>
__declspec(
noinline
) auto then(const _Function& _Func, const task_options& _TaskOptions = task_options()) const -> typename details::_ContinuationTypeTraits<_Function, void>::_TaskOfType;
template<
typename _Function
>
__declspec(
noinline
) auto then(const _Function& _Func, cancellation_token _CancellationToken, task_continuation_context _ContinuationContext) const -> typename details::_ContinuationTypeTraits<_Function, void>::_TaskOfType;
参数
_Function
此任务将调用的函数对象的类型。_Func
此任务完成时要执行的延续函数。 此延续函数必须将 result_type 或 task<result_type> 的变量作为输入,其中 result_type 是此任务产生的结果的类型。_TaskOptions
任务选项包括取消标记、计划程序和延续上下文。 默认情况下,前面的 3 个选项是从前面的任务继承的_CancellationToken
要与延续任务相关联的取消标记。 创建时不带取消标记的延续任务将继承其前面的任务的标记。_ContinuationContext
用于指定执行延续的位置的变量。 此变量仅在用于 Windows 应用商店风格的应用时才有用。 有关详细信息,请参阅 task_continuation_context
返回值
新创建的延续任务。 返回任务的结果类型取决于 _Func 返回的内容。
备注
采用返回 Windows::Foundation::IAsyncInfo 接口的 lambda 或函子的 then 的重载仅适用于 Windows 应用商店应用。
有关如何使用任务延续构成异步工作的详细信息,请参阅任务并行(并发运行时)。
要求
**标头:**pplxtasks.h
**命名空间:**pplx