共用方式為


task::then 方法

將接續工作加入至工作。

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_typetask<result_type> 的變數做為輸入,其中 result_type 是這個工作所產生結果的類型。

  • _TaskOptions
    工作選項包括取消語彙基元、排程器和接續內容。 前 3 個選項預設會從前項工作繼承

  • _CancellationToken
    要與接續工作產生關聯的取消語彙基元。 所建立不含取消語彙基元的接續工作將會繼承其前項工作的語彙基元。

  • _ContinuationContext
    指定接續執行所在位置的變數。 在 Windows 市集樣式應用程式中使用時,此變數才能發揮效用。 如需詳細資訊,請參閱 task_continuation_context

傳回值

新建立的接續工作。 所傳回工作的結果類型取決於 _Func 傳回哪些項目。

備註

then 多載可接受傳回 Windows::Foundation::IAsyncInfo 介面的 Lambda 或仿函數 (functor),只讓 Windows 市集應用程式使用。

如需如何使用接續工作組成非同步工作的詳細資訊,請參閱工作平行處理原則 (並行執行階段)

需求

**標頭:**ppltasks.h

**命名空間:**concurrency

請參閱

參考

task 類別 (並行執行階段)