Task.ContinueWith 메서드

정의

대상이 Task 완료되면 비동기적으로 실행되는 연속을 만듭니다.

오버로드

Name Description
ContinueWith(Action<Task,Object>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler)

호출자가 제공한 상태 정보 및 취소 토큰을 수신하고 대상이 Task 완료될 때 실행되는 연속 작업을 만듭니다. 연속 작업은 지정된 조건 집합에 따라 실행되며 지정된 스케줄러를 사용합니다.

ContinueWith(Action<Task>, CancellationToken, TaskContinuationOptions, TaskScheduler)

대상 작업이 지정된 TaskContinuationOptions작업에 따라 경쟁할 때 실행되는 연속 작업을 만듭니다. 연속 작업은 취소 토큰을 수신하고 지정된 스케줄러를 사용합니다.

ContinueWith(Action<Task,Object>, Object, TaskScheduler)

호출자가 제공한 상태 정보를 수신하고 대상이 Task 완료되면 비동기적으로 실행되는 연속을 만듭니다. 연속 작업은 지정된 스케줄러를 사용합니다.

ContinueWith(Action<Task,Object>, Object, TaskContinuationOptions)

호출자가 제공한 상태 정보를 수신하고 대상이 Task 완료되면 실행되는 연속을 만듭니다. 연속은 지정된 조건 집합에 따라 실행됩니다.

ContinueWith(Action<Task,Object>, Object, CancellationToken)

호출자가 제공한 상태 정보 및 취소 토큰을 수신하고 대상이 Task 완료될 때 비동기적으로 실행되는 연속 작업을 만듭니다.

ContinueWith(Action<Task,Object>, Object)

호출자가 제공한 상태 정보를 수신하고 대상이 Task 완료되면 실행되는 연속을 만듭니다.

ContinueWith(Action<Task>, TaskContinuationOptions)

지정된 TaskContinuationOptions에 따라 대상 작업이 완료될 때 실행되는 연속 작업을 만듭니다.

ContinueWith(Action<Task>, CancellationToken)

취소 토큰을 수신하고 대상이 Task 완료되면 비동기적으로 실행되는 연속 작업을 만듭니다.

ContinueWith(Action<Task>)

대상이 Task 완료되면 비동기적으로 실행되는 연속을 만듭니다.

ContinueWith(Action<Task>, TaskScheduler)

대상이 Task 완료되면 비동기적으로 실행되는 연속을 만듭니다. 연속 작업은 지정된 스케줄러를 사용합니다.

ContinueWith<TResult>(Func<Task,Object,TResult>, Object, TaskContinuationOptions)

대상이 Task 완료될 때 지정된 작업 연속 옵션에 따라 실행되는 연속 작업을 만듭니다. 연속은 호출자가 제공한 상태 정보를 받습니다.

ContinueWith<TResult>(Func<Task,Object,TResult>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler)

대상이 Task 완료되고 값을 반환할 때 지정된 작업 연속 옵션에 따라 실행되는 연속 작업을 만듭니다. 연속은 호출자가 제공한 상태 정보 및 취소 토큰을 수신하고 지정된 스케줄러를 사용합니다.

ContinueWith<TResult>(Func<Task,TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler)

지정된 연속 옵션에 따라 실행되는 연속 작업을 만들고 값을 반환합니다. 연속 작업은 취소 토큰을 전달하고 지정된 스케줄러를 사용합니다.

ContinueWith<TResult>(Func<Task,Object,TResult>, Object, TaskScheduler)

대상이 Task 완료되면 비동기적으로 실행되는 연속을 만듭니다. 연속은 호출자 제공 상태 정보를 수신하고 지정된 스케줄러를 사용합니다.

ContinueWith<TResult>(Func<Task,Object,TResult>, Object, CancellationToken)

대상이 Task 완료되고 값을 반환할 때 비동기적으로 실행되는 연속을 만듭니다. 연속은 호출자가 제공한 상태 정보 및 취소 토큰을 받습니다.

ContinueWith<TResult>(Func<Task,Object,TResult>, Object)

호출자가 제공한 상태 정보를 수신하고 대상이 Task 완료되고 값을 반환할 때 비동기적으로 실행되는 연속을 만듭니다.

ContinueWith<TResult>(Func<Task,TResult>, TaskContinuationOptions)

지정된 연속 옵션에 따라 실행되는 연속 작업을 만들고 값을 반환합니다.

ContinueWith<TResult>(Func<Task,TResult>, CancellationToken)

대상이 Task 완료되고 값을 반환할 때 비동기적으로 실행되는 연속을 만듭니다. 연속은 취소 토큰을 받습니다.

ContinueWith<TResult>(Func<Task,TResult>)

대상이 Task<TResult> 완료되고 값을 반환할 때 비동기적으로 실행되는 연속을 만듭니다.

ContinueWith<TResult>(Func<Task,TResult>, TaskScheduler)

대상이 Task 완료되고 값을 반환할 때 비동기적으로 실행되는 연속을 만듭니다. 연속 작업은 지정된 스케줄러를 사용합니다.

ContinueWith(Action<Task,Object>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler)

호출자가 제공한 상태 정보 및 취소 토큰을 수신하고 대상이 Task 완료될 때 실행되는 연속 작업을 만듭니다. 연속 작업은 지정된 조건 집합에 따라 실행되며 지정된 스케줄러를 사용합니다.

public:
 System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task ^, System::Object ^> ^ continuationAction, System::Object ^ state, System::Threading::CancellationToken cancellationToken, System::Threading::Tasks::TaskContinuationOptions continuationOptions, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task ContinueWith(Action<System.Threading.Tasks.Task,object> continuationAction, object state, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);
member this.ContinueWith : Action<System.Threading.Tasks.Task, obj> * obj * System.Threading.CancellationToken * System.Threading.Tasks.TaskContinuationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task
Public Function ContinueWith (continuationAction As Action(Of Task, Object), state As Object, cancellationToken As CancellationToken, continuationOptions As TaskContinuationOptions, scheduler As TaskScheduler) As Task

매개 변수

continuationAction
Action<Task,Object>

완료 시 실행할 Task 작업입니다. 실행하면 대리자가 완료된 작업과 호출자가 제공한 상태 개체를 인수로 전달합니다.

state
Object

연속 작업에서 사용할 데이터를 나타내는 개체입니다.

cancellationToken
CancellationToken

CancellationToken 새 연속 작업에 할당되는 작업입니다.

continuationOptions
TaskContinuationOptions

연속 작업이 예약된 시기 및 동작 방식에 대한 옵션입니다. 여기에는 조건(예: OnlyOnCanceled.)과 같은 실행 옵션이 ExecuteSynchronously포함됩니다.

scheduler
TaskScheduler

TaskScheduler 연속 작업과 연결하고 해당 실행에 사용할 대상입니다.

반품

새 연속입니다 Task.

예외

인수는 scheduler .입니다 null.

인수가 continuationOptions 잘못된 값을 TaskContinuationOptions지정합니다.

제공된 CancellationToken 내용은 이미 삭제되었습니다.

설명

반환 Task 된 작업은 현재 작업이 완료될 때까지 실행 예약되지 않습니다. 매개 변수를 통해 continuationOptions 지정된 조건이 충족되지 않으면 연속 작업이 예약되지 않고 취소됩니다.

적용 대상

ContinueWith(Action<Task>, CancellationToken, TaskContinuationOptions, TaskScheduler)

대상 작업이 지정된 TaskContinuationOptions작업에 따라 경쟁할 때 실행되는 연속 작업을 만듭니다. 연속 작업은 취소 토큰을 수신하고 지정된 스케줄러를 사용합니다.

public:
 System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task ^> ^ continuationAction, System::Threading::CancellationToken cancellationToken, System::Threading::Tasks::TaskContinuationOptions continuationOptions, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task ContinueWith(Action<System.Threading.Tasks.Task> continuationAction, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);
member this.ContinueWith : Action<System.Threading.Tasks.Task> * System.Threading.CancellationToken * System.Threading.Tasks.TaskContinuationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task
Public Function ContinueWith (continuationAction As Action(Of Task), cancellationToken As CancellationToken, continuationOptions As TaskContinuationOptions, scheduler As TaskScheduler) As Task

매개 변수

continuationAction
Action<Task>

지정된 에 따라 실행할 작업입니다 continuationOptions. 실행하면 대리자가 완료된 작업을 인수로 전달합니다.

cancellationToken
CancellationToken

CancellationToken 새 연속 작업에 할당되는 작업입니다.

continuationOptions
TaskContinuationOptions

연속 작업이 예약된 시기 및 동작 방식에 대한 옵션입니다. 여기에는 조건(예: OnlyOnCanceled.)과 같은 실행 옵션이 ExecuteSynchronously포함됩니다.

scheduler
TaskScheduler

TaskScheduler 연속 작업과 연결하고 해당 실행에 사용할 대상입니다.

반품

새 연속입니다 Task.

예외

CancellationTokenSource 토큰을 만든 토큰이 이미 삭제되었습니다.

인수가 continuationAction null입니다.

-또는-

인수가 scheduler null입니다.

인수가 continuationOptions 잘못된 값을 TaskContinuationOptions지정합니다.

예제

다음은 ContinueWith를 사용하여 백그라운드 및 사용자 인터페이스 스레드 모두에서 작업을 실행하는 예제입니다.

private void Button1_Click(object sender, EventArgs e)
{
   var backgroundScheduler = TaskScheduler.Default;
   var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
   Task.Factory.StartNew(delegate { DoBackgroundComputation(); },
                         backgroundScheduler).
   ContinueWith(delegate { UpdateUI(); }, uiScheduler).
                ContinueWith(delegate { DoAnotherBackgroundComputation(); },
                             backgroundScheduler).
                ContinueWith(delegate { UpdateUIAgain(); }, uiScheduler);
}
Private Sub Button1_Click(ByVal sender As System.Object,
                          ByVal e As System.EventArgs) Handles Button1.Click
   Dim backgroundScheduler = TaskScheduler.Default
   Dim uiScheduler = TaskScheduler.FromCurrentSynchronizationContext()

   Task.Factory.StartNew(Sub()
                           DoBackgroundComputation()
                         End Sub, backgroundScheduler).ContinueWith(Sub(t)
                            UpdateUI()
                         End Sub, uiScheduler).ContinueWith(Sub(t)
                            DoAnotherBackgroundComputation()
                         End Sub, backgroundScheduler).ContinueWith(Sub(t)
                            UpdateUIAgain()
                         End Sub, uiScheduler)
End Sub

설명

반환 Task 된 작업은 현재 작업이 완료될 때까지 실행 예약되지 않습니다. 매개 변수를 통해 continuationOptions 지정된 조건이 충족되지 않으면 연속 작업이 예약되지 않고 취소됩니다.

적용 대상

ContinueWith(Action<Task,Object>, Object, TaskScheduler)

호출자가 제공한 상태 정보를 수신하고 대상이 Task 완료되면 비동기적으로 실행되는 연속을 만듭니다. 연속 작업은 지정된 스케줄러를 사용합니다.

public:
 System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task ^, System::Object ^> ^ continuationAction, System::Object ^ state, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task ContinueWith(Action<System.Threading.Tasks.Task,object> continuationAction, object state, System.Threading.Tasks.TaskScheduler scheduler);
member this.ContinueWith : Action<System.Threading.Tasks.Task, obj> * obj * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task
Public Function ContinueWith (continuationAction As Action(Of Task, Object), state As Object, scheduler As TaskScheduler) As Task

매개 변수

continuationAction
Action<Task,Object>

완료 시 실행할 Task 작업입니다. 실행하면 대리자가 완료된 작업과 호출자가 제공한 상태 개체를 인수로 전달합니다.

state
Object

연속 작업에서 사용할 데이터를 나타내는 개체입니다.

scheduler
TaskScheduler

TaskScheduler 연속 작업과 연결하고 해당 실행에 사용할 대상입니다.

반품

새 연속입니다 Task.

예외

인수는 scheduler .입니다 null.

설명

반환 Task 된 작업은 현재 작업이 완료될 때까지 실행이 완료되거나, 처리되지 않은 예외로 인해 오류가 발생하거나, 취소로 인해 일찍 종료될 때까지 실행되도록 예약되지 않습니다.

적용 대상

ContinueWith(Action<Task,Object>, Object, TaskContinuationOptions)

호출자가 제공한 상태 정보를 수신하고 대상이 Task 완료되면 실행되는 연속을 만듭니다. 연속은 지정된 조건 집합에 따라 실행됩니다.

public:
 System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task ^, System::Object ^> ^ continuationAction, System::Object ^ state, System::Threading::Tasks::TaskContinuationOptions continuationOptions);
public System.Threading.Tasks.Task ContinueWith(Action<System.Threading.Tasks.Task,object> continuationAction, object state, System.Threading.Tasks.TaskContinuationOptions continuationOptions);
member this.ContinueWith : Action<System.Threading.Tasks.Task, obj> * obj * System.Threading.Tasks.TaskContinuationOptions -> System.Threading.Tasks.Task
Public Function ContinueWith (continuationAction As Action(Of Task, Object), state As Object, continuationOptions As TaskContinuationOptions) As Task

매개 변수

continuationAction
Action<Task,Object>

완료 시 실행할 Task 작업입니다. 실행하면 대리자가 완료된 작업과 호출자가 제공한 상태 개체를 인수로 전달합니다.

state
Object

연속 작업에서 사용할 데이터를 나타내는 개체입니다.

continuationOptions
TaskContinuationOptions

연속 작업이 예약된 시기 및 동작 방식에 대한 옵션입니다. 여기에는 조건(예: OnlyOnCanceled.)과 같은 실행 옵션이 ExecuteSynchronously포함됩니다.

반품

새 연속입니다 Task.

예외

인수는 continuationAction .입니다 null.

인수가 continuationOptions 잘못된 값을 TaskContinuationOptions지정합니다.

설명

반환 Task 된 작업은 현재 작업이 완료될 때까지 실행 예약되지 않습니다. 매개 변수를 통해 continuationOptions 지정된 연속 조건이 충족되지 않으면 연속 작업이 예약되지 않고 취소됩니다.

적용 대상

ContinueWith(Action<Task,Object>, Object, CancellationToken)

호출자가 제공한 상태 정보 및 취소 토큰을 수신하고 대상이 Task 완료될 때 비동기적으로 실행되는 연속 작업을 만듭니다.

public:
 System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task ^, System::Object ^> ^ continuationAction, System::Object ^ state, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task ContinueWith(Action<System.Threading.Tasks.Task,object> continuationAction, object state, System.Threading.CancellationToken cancellationToken);
member this.ContinueWith : Action<System.Threading.Tasks.Task, obj> * obj * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function ContinueWith (continuationAction As Action(Of Task, Object), state As Object, cancellationToken As CancellationToken) As Task

매개 변수

continuationAction
Action<Task,Object>

완료 시 실행할 Task 작업입니다. 실행하면 대리자가 완료된 작업과 호출자가 제공한 상태 개체를 인수로 전달합니다.

state
Object

연속 작업에서 사용할 데이터를 나타내는 개체입니다.

cancellationToken
CancellationToken

CancellationToken 새 연속 작업에 할당되는 작업입니다.

반품

새 연속입니다 Task.

예외

인수는 continuationAction .입니다 null.

제공된 CancellationToken 내용은 이미 삭제되었습니다.

설명

반환 Task 된 작업은 현재 작업이 완료될 때까지 실행이 완료되거나, 처리되지 않은 예외로 인해 오류가 발생하거나, 취소로 인해 일찍 종료될 때까지 실행되도록 예약되지 않습니다.

적용 대상

ContinueWith(Action<Task,Object>, Object)

호출자가 제공한 상태 정보를 수신하고 대상이 Task 완료되면 실행되는 연속을 만듭니다.

public:
 System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task ^, System::Object ^> ^ continuationAction, System::Object ^ state);
public System.Threading.Tasks.Task ContinueWith(Action<System.Threading.Tasks.Task,object> continuationAction, object state);
member this.ContinueWith : Action<System.Threading.Tasks.Task, obj> * obj -> System.Threading.Tasks.Task
Public Function ContinueWith (continuationAction As Action(Of Task, Object), state As Object) As Task

매개 변수

continuationAction
Action<Task,Object>

작업이 완료되면 실행할 작업입니다. 실행하면 대리자가 완료된 작업과 호출자 제공 상태 개체를 인수로 전달합니다.

state
Object

연속 작업에서 사용할 데이터를 나타내는 개체입니다.

반품

새 연속 작업입니다.

예외

인수는 continuationAction .입니다 null.

설명

반환 Task 된 작업은 현재 작업이 완료될 때까지 실행되도록 예약되지 않습니다. 완료로 인해 완료되었는지, 처리되지 않은 예외로 인한 오류로 인해 오류가 발생했는지 또는 취소로 인해 일찍 종료되는지 여부입니다.

적용 대상

ContinueWith(Action<Task>, TaskContinuationOptions)

지정된 TaskContinuationOptions에 따라 대상 작업이 완료될 때 실행되는 연속 작업을 만듭니다.

public:
 System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task ^> ^ continuationAction, System::Threading::Tasks::TaskContinuationOptions continuationOptions);
public System.Threading.Tasks.Task ContinueWith(Action<System.Threading.Tasks.Task> continuationAction, System.Threading.Tasks.TaskContinuationOptions continuationOptions);
member this.ContinueWith : Action<System.Threading.Tasks.Task> * System.Threading.Tasks.TaskContinuationOptions -> System.Threading.Tasks.Task
Public Function ContinueWith (continuationAction As Action(Of Task), continuationOptions As TaskContinuationOptions) As Task

매개 변수

continuationAction
Action<Task>

지정된 에 따라 실행할 작업입니다 continuationOptions. 실행하면 대리자가 완료된 작업을 인수로 전달합니다.

continuationOptions
TaskContinuationOptions

연속 작업이 예약된 시기 및 동작 방식에 대한 옵션입니다. 여기에는 조건(예: OnlyOnCanceled.)과 같은 실행 옵션이 ExecuteSynchronously포함됩니다.

반품

새 연속입니다 Task.

예외

인수가 continuationAction null입니다.

인수가 continuationOptions 잘못된 값을 TaskContinuationOptions지정합니다.

예제

다음 예제에서는 선행 작업이 완료될 때 연속 작업이 동기적으로 실행되도록 지정하는 데 사용하는 TaskContinuationOptions 방법을 보여 줍니다. (지정된 작업이 호출될 때까지 ContinueWith 이미 완료된 경우 동기 연속은 스레드 호출 ContinueWith에서 실행됩니다.)

public class TaskCounter
{
   private volatile int _count;

   public void Track(Task t)
   {
      if (t == null) throw new ArgumentNullException("t");
      Interlocked.Increment(ref _count);
      t.ContinueWith(ct => Interlocked.Decrement(ref _count), TaskContinuationOptions.ExecuteSynchronously);
   }

   public int NumberOfActiveTasks { get { return _count; } }
}
Public Class TaskCounter
   Private _count as Integer

   Public Sub Track(ByVal t as Task)
      If t is Nothing Then Throw New ArgumentNullException("t")
      Interlocked.Increment(_count)
      t.ContinueWith(Sub(ct)
                        Interlocked.Decrement(_count)
                     End Sub,
                     TaskContinuationOptions.ExecuteSynchronously)
   End Sub

   Public ReadOnly Property NumberOfActiveTasks As Integer
      Get
         Return _count
      End Get
   End Property
End Class

설명

반환 Task 된 작업은 현재 작업이 완료될 때까지 실행 예약되지 않습니다. 매개 변수를 통해 continuationOptions 지정된 연속 조건이 충족되지 않으면 연속 작업이 예약되지 않고 취소됩니다.

적용 대상

ContinueWith(Action<Task>, CancellationToken)

취소 토큰을 수신하고 대상이 Task 완료되면 비동기적으로 실행되는 연속 작업을 만듭니다.

public:
 System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task ^> ^ continuationAction, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task ContinueWith(Action<System.Threading.Tasks.Task> continuationAction, System.Threading.CancellationToken cancellationToken);
member this.ContinueWith : Action<System.Threading.Tasks.Task> * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function ContinueWith (continuationAction As Action(Of Task), cancellationToken As CancellationToken) As Task

매개 변수

continuationAction
Action<Task>

완료 시 실행할 Task 작업입니다. 실행하면 대리자가 완료된 작업을 인수로 전달합니다.

cancellationToken
CancellationToken

CancellationToken 새 연속 작업에 할당되는 작업입니다.

반품

새 연속입니다 Task.

예외

CancellationTokenSource 토큰을 만든 토큰이 이미 삭제되었습니다.

인수가 continuationAction null입니다.

설명

반환 Task 된 작업은 현재 작업이 완료될 때까지 실행이 완료되거나, 처리되지 않은 예외로 인해 오류가 발생하거나, 취소로 인해 일찍 종료될 때까지 실행되도록 예약되지 않습니다.

적용 대상

ContinueWith(Action<Task>)

대상이 Task 완료되면 비동기적으로 실행되는 연속을 만듭니다.

public:
 System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task ^> ^ continuationAction);
public System.Threading.Tasks.Task ContinueWith(Action<System.Threading.Tasks.Task> continuationAction);
member this.ContinueWith : Action<System.Threading.Tasks.Task> -> System.Threading.Tasks.Task
Public Function ContinueWith (continuationAction As Action(Of Task)) As Task

매개 변수

continuationAction
Action<Task>

완료 시 실행할 Task 작업입니다. 실행하면 대리자가 완료된 작업을 인수로 전달합니다.

반품

새 연속입니다 Task.

예외

인수는 continuationAction .입니다 null.

예제

다음 예제에서는 임의의 날짜 및 시간 값이 100인 배열을 채우는 작업을 정의합니다. 배열이 ContinueWith(Action<Task>) 완전히 채워지면 이 메서드를 사용하여 가장 빠른 날짜 값과 최신 날짜 값을 선택합니다.

using System;
using System.Threading.Tasks;

public class Example
{
   public static void Main()
   {
      var firstTask = Task.Factory.StartNew( () => {
                               Random rnd = new Random();
                               DateTime[] dates = new DateTime[100];
                               Byte[] buffer = new Byte[8];
                               int ctr = dates.GetLowerBound(0);
                               while (ctr <= dates.GetUpperBound(0)) {
                                  rnd.NextBytes(buffer);
                                  long ticks = BitConverter.ToInt64(buffer, 0);
                                  if (ticks <= DateTime.MinValue.Ticks | ticks >= DateTime.MaxValue.Ticks)
                                     continue;

                                  dates[ctr] = new DateTime(ticks);
                                  ctr++;
                               }
                               return dates;
                            } ); 
                         
      Task continuationTask = firstTask.ContinueWith( (antecedent) => {
                             DateTime[] dates = antecedent.Result;
                             DateTime earliest = dates[0];
                             DateTime latest = earliest;
                             
                             for (int ctr = dates.GetLowerBound(0) + 1; ctr <= dates.GetUpperBound(0); ctr++) {
                                if (dates[ctr] < earliest) earliest = dates[ctr];
                                if (dates[ctr] > latest) latest = dates[ctr];
                             }
                             Console.WriteLine("Earliest date: {0}", earliest);
                             Console.WriteLine("Latest date: {0}", latest);
                          } );                      
      // Since a console application otherwise terminates, wait for the continuation to complete.
     continuationTask.Wait();
   }
}
// The example displays output like the following:
//       Earliest date: 2/11/0110 12:03:41 PM
//       Latest date: 7/29/9989 2:14:49 PM
open System
open System.Threading.Tasks

let firstTask =
    Task.Factory.StartNew(fun () ->
        let rnd = Random()
        let dates = Array.zeroCreate 100
        let buffer = Array.zeroCreate 8
        let mutable i = dates.GetLowerBound 0

        while i <= dates.GetUpperBound 0 do
            rnd.NextBytes buffer
            let ticks = BitConverter.ToInt64(buffer, 0)

            if ticks > DateTime.MinValue.Ticks && ticks < DateTime.MaxValue.Ticks then
                dates[i] <- DateTime ticks
                i <- i + 1

        dates)

let continuationTask =
    firstTask.ContinueWith(
        Action<Task<DateTime[]>>(fun antecedent ->
            let dates: DateTime[] = antecedent.Result
            let mutable earliest = dates[0]
            let mutable latest = earliest

            for i = dates.GetLowerBound 0 + 1 to dates.GetUpperBound 0 do
                if dates.[i] < earliest then
                    earliest <- dates.[i]

                if dates.[i] > latest then
                    latest <- dates.[i]

            printfn $"Earliest date: {earliest}"
            printfn $"Latest date: {latest}")
    )
// Since a console application otherwise terminates, wait for the continuation to complete.
continuationTask.Wait()


// The example displays output like the following:
//       Earliest date: 2/11/0110 12:03:41 PM
//       Latest date: 7/29/9989 2:14:49 PM
Imports System.Threading.Tasks

Module Example
   Public Sub Main()
      Dim firstTask = Task.Factory.StartNew( Function()
                               Dim rnd As New Random()
                               Dim dates(99) As Date
                               Dim buffer(7) As Byte
                               Dim ctr As Integer = dates.GetLowerBound(0)
                               Do While ctr <= dates.GetUpperBound(0)
                                  rnd.NextBytes(buffer)
                                  Dim ticks As Long = BitConverter.ToInt64(buffer, 0)
                                  If ticks <= DateTime.MinValue.Ticks Or ticks >= DateTime.MaxValue.Ticks Then Continue Do

                                  dates(ctr) = New Date(ticks)
                                  ctr += 1
                               Loop
                               Return dates
                            End Function )
                         
      Dim continuationTask As Task = firstTask.ContinueWith( Sub(antecedent)
                             Dim dates() As Date = antecedent.Result
                             Dim earliest As Date = dates(0)
                             Dim latest As Date = earliest
                             
                             For ctr As Integer = dates.GetLowerBound(0) + 1 To dates.GetUpperBound(0)
                                If dates(ctr) < earliest Then earliest = dates(ctr)
                                If dates(ctr) > latest Then latest = dates(ctr)
                             Next
                             Console.WriteLine("Earliest date: {0}", earliest)
                             Console.WriteLine("Latest date: {0}", latest)
                          End Sub)                      
      ' Since a console application otherwise terminates, wait for the continuation to complete.
      continuationTask.Wait()
   End Sub
End Module
' The example displays output like the following:
'       Earliest date: 2/11/0110 12:03:41 PM
'       Latest date: 7/29/9989 2:14:49 PM

연속 작업이 실행 Wait() 되기 전에 콘솔 애플리케이션을 종료할 수 있으므로 예제가 끝나기 전에 연속 실행이 완료되도록 하기 위해 메서드가 호출됩니다.

추가 예제는 연속 작업을 사용하여 작업 연결(Chaining Tasks)을 참조하세요.

설명

반환 Task 된 작업은 현재 작업이 완료될 때까지 실행이 완료되거나, 처리되지 않은 예외로 인해 오류가 발생하거나, 취소로 인해 일찍 종료될 때까지 실행되도록 예약되지 않습니다.

적용 대상

ContinueWith(Action<Task>, TaskScheduler)

대상이 Task 완료되면 비동기적으로 실행되는 연속을 만듭니다. 연속 작업은 지정된 스케줄러를 사용합니다.

public:
 System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task ^> ^ continuationAction, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task ContinueWith(Action<System.Threading.Tasks.Task> continuationAction, System.Threading.Tasks.TaskScheduler scheduler);
member this.ContinueWith : Action<System.Threading.Tasks.Task> * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task
Public Function ContinueWith (continuationAction As Action(Of Task), scheduler As TaskScheduler) As Task

매개 변수

continuationAction
Action<Task>

완료 시 실행할 Task 작업입니다. 실행하면 대리자가 완료된 작업을 인수로 전달합니다.

scheduler
TaskScheduler

TaskScheduler 연속 작업과 연결하고 해당 실행에 사용할 대상입니다.

반품

새 연속입니다 Task.

예외

Task 삭제되었습니다.

인수는 continuationAction .입니다 null.

-또는-

인수가 scheduler null입니다.

설명

반환 Task 된 작업은 현재 작업이 완료될 때까지 실행이 완료되거나, 처리되지 않은 예외로 인해 오류가 발생하거나, 취소로 인해 일찍 종료될 때까지 실행되도록 예약되지 않습니다.

적용 대상

ContinueWith<TResult>(Func<Task,Object,TResult>, Object, TaskContinuationOptions)

대상이 Task 완료될 때 지정된 작업 연속 옵션에 따라 실행되는 연속 작업을 만듭니다. 연속은 호출자가 제공한 상태 정보를 받습니다.

public:
generic <typename TResult>
 System::Threading::Tasks::Task<TResult> ^ ContinueWith(Func<System::Threading::Tasks::Task ^, System::Object ^, TResult> ^ continuationFunction, System::Object ^ state, System::Threading::Tasks::TaskContinuationOptions continuationOptions);
public System.Threading.Tasks.Task<TResult> ContinueWith<TResult>(Func<System.Threading.Tasks.Task,object,TResult> continuationFunction, object state, System.Threading.Tasks.TaskContinuationOptions continuationOptions);
member this.ContinueWith : Func<System.Threading.Tasks.Task, obj, 'Result> * obj * System.Threading.Tasks.TaskContinuationOptions -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWith(Of TResult) (continuationFunction As Func(Of Task, Object, TResult), state As Object, continuationOptions As TaskContinuationOptions) As Task(Of TResult)

형식 매개 변수

TResult

연속으로 생성된 결과의 형식입니다.

매개 변수

continuationFunction
Func<Task,Object,TResult>

완료 시 실행할 Task 함수입니다. 실행하면 대리자가 완료된 작업과 호출자가 제공한 상태 개체를 인수로 전달합니다.

state
Object

연속 함수에서 사용할 데이터를 나타내는 개체입니다.

continuationOptions
TaskContinuationOptions

연속 작업이 예약된 시기 및 동작 방식에 대한 옵션입니다. 여기에는 조건(예: OnlyOnCanceled.)과 같은 실행 옵션이 ExecuteSynchronously포함됩니다.

반품

새 연속입니다 Task<TResult>.

예외

인수는 continuationFunction .입니다 null.

인수가 continuationOptions 잘못된 값을 TaskContinuationOptions지정합니다.

설명

반환 Task<TResult> 된 작업은 현재 작업이 완료될 때까지 실행 예약되지 않습니다. 매개 변수를 통해 continuationOptions 지정된 연속 조건이 충족되지 않으면 연속 작업이 예약되지 않고 취소됩니다.

적용 대상

ContinueWith<TResult>(Func<Task,Object,TResult>, Object, CancellationToken, TaskContinuationOptions, TaskScheduler)

대상이 Task 완료되고 값을 반환할 때 지정된 작업 연속 옵션에 따라 실행되는 연속 작업을 만듭니다. 연속은 호출자가 제공한 상태 정보 및 취소 토큰을 수신하고 지정된 스케줄러를 사용합니다.

public:
generic <typename TResult>
 System::Threading::Tasks::Task<TResult> ^ ContinueWith(Func<System::Threading::Tasks::Task ^, System::Object ^, TResult> ^ continuationFunction, System::Object ^ state, System::Threading::CancellationToken cancellationToken, System::Threading::Tasks::TaskContinuationOptions continuationOptions, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task<TResult> ContinueWith<TResult>(Func<System.Threading.Tasks.Task,object,TResult> continuationFunction, object state, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);
member this.ContinueWith : Func<System.Threading.Tasks.Task, obj, 'Result> * obj * System.Threading.CancellationToken * System.Threading.Tasks.TaskContinuationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWith(Of TResult) (continuationFunction As Func(Of Task, Object, TResult), state As Object, cancellationToken As CancellationToken, continuationOptions As TaskContinuationOptions, scheduler As TaskScheduler) As Task(Of TResult)

형식 매개 변수

TResult

연속으로 생성된 결과의 형식입니다.

매개 변수

continuationFunction
Func<Task,Object,TResult>

완료 시 실행할 Task 함수입니다. 실행하면 대리자가 완료된 작업과 호출자가 제공한 상태 개체를 인수로 전달합니다.

state
Object

연속 함수에서 사용할 데이터를 나타내는 개체입니다.

cancellationToken
CancellationToken

CancellationToken 새 연속 작업에 할당되는 작업입니다.

continuationOptions
TaskContinuationOptions

연속 작업이 예약된 시기 및 동작 방식에 대한 옵션입니다. 여기에는 조건(예: OnlyOnCanceled.)과 같은 실행 옵션이 ExecuteSynchronously포함됩니다.

scheduler
TaskScheduler

TaskScheduler 연속 작업과 연결하고 해당 실행에 사용할 대상입니다.

반품

새 연속입니다 Task<TResult>.

예외

인수는 scheduler .입니다 null.

인수가 continuationOptions 잘못된 값을 TaskContinuationOptions지정합니다.

제공된 CancellationToken 내용은 이미 삭제되었습니다.

설명

반환 Task<TResult> 된 작업은 현재 작업이 완료될 때까지 실행 예약되지 않습니다. 매개 변수를 통해 continuationOptions 지정된 조건이 충족되지 않으면 연속 작업이 예약되지 않고 취소됩니다.

적용 대상

ContinueWith<TResult>(Func<Task,TResult>, CancellationToken, TaskContinuationOptions, TaskScheduler)

지정된 연속 옵션에 따라 실행되는 연속 작업을 만들고 값을 반환합니다. 연속 작업은 취소 토큰을 전달하고 지정된 스케줄러를 사용합니다.

public:
generic <typename TResult>
 System::Threading::Tasks::Task<TResult> ^ ContinueWith(Func<System::Threading::Tasks::Task ^, TResult> ^ continuationFunction, System::Threading::CancellationToken cancellationToken, System::Threading::Tasks::TaskContinuationOptions continuationOptions, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task<TResult> ContinueWith<TResult>(Func<System.Threading.Tasks.Task,TResult> continuationFunction, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);
member this.ContinueWith : Func<System.Threading.Tasks.Task, 'Result> * System.Threading.CancellationToken * System.Threading.Tasks.TaskContinuationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWith(Of TResult) (continuationFunction As Func(Of Task, TResult), cancellationToken As CancellationToken, continuationOptions As TaskContinuationOptions, scheduler As TaskScheduler) As Task(Of TResult)

형식 매개 변수

TResult

연속으로 생성된 결과의 형식입니다.

매개 변수

continuationFunction
Func<Task,TResult>

지정된 continuationOptions. When run에 따라 실행할 함수는 대리자가 완료된 작업을 인수로 전달합니다.

cancellationToken
CancellationToken

CancellationToken 새 연속 작업에 할당되는 작업입니다.

continuationOptions
TaskContinuationOptions

연속 작업이 예약된 시기 및 동작 방식에 대한 옵션입니다. 여기에는 조건(예: OnlyOnCanceled.)과 같은 실행 옵션이 ExecuteSynchronously포함됩니다.

scheduler
TaskScheduler

TaskScheduler 연속 작업과 연결하고 해당 실행에 사용할 대상입니다.

반품

새 연속입니다 Task<TResult>.

예외

Task 삭제되었습니다.

-또는-

CancellationTokenSource 토큰을 만든 토큰이 이미 삭제되었습니다.

인수가 continuationFunction null입니다.

-또는-

인수가 scheduler null입니다.

인수가 continuationOptions 잘못된 값을 TaskContinuationOptions지정합니다.

예제

다음 예제에서는 연속 옵션과 함께 ContinueWith 메서드를 사용하는 방법을 보여줍니다.

using System;
using System.Threading;
using System.Threading.Tasks;

class ContinuationOptionsDemo
{
    // Demonstrated features:
    //      TaskContinuationOptions
    //		Task.ContinueWith()
    // 		Task.Factory
    //		Task.Wait()
    // Expected results:
    // 		This sample demonstrates branched continuation sequences - Task+Commit or Task+Rollback.
    //      Notice that no if statements are used.
    //		The first sequence is successful - tran1 and commitTran1 are executed. rollbackTran1 is canceled.
    //		The second sequence is unsuccessful - tran2 and rollbackTran2 are executed. tran2 is faulted, and commitTran2 is canceled.
    // Documentation:
    //		http://msdn.microsoft.com/library/system.threading.tasks.taskcontinuationoptions(VS.100).aspx
    static void Main()
    {
        Action success = () => Console.WriteLine("Task={0}, Thread={1}: Begin successful transaction",
                                                Task.CurrentId, Thread.CurrentThread.ManagedThreadId);
        Action failure = () =>
        {
            Console.WriteLine("Task={0}, Thread={1}: Begin transaction and encounter an error",
                                Task.CurrentId, Thread.CurrentThread.ManagedThreadId);
            throw new InvalidOperationException("SIMULATED EXCEPTION");
        };

        Action<Task> commit = (antecendent) => Console.WriteLine("Task={0}, Thread={1}: Commit transaction",
                                                                Task.CurrentId, Thread.CurrentThread.ManagedThreadId);
        Action<Task> rollback = (antecendent) =>
        {
            // "Observe" your antecedent's exception so as to avoid an exception
            // being thrown on the finalizer thread
            var unused = antecendent.Exception;

            Console.WriteLine("Task={0}, Thread={1}: Rollback transaction",
                  Task.CurrentId, Thread.CurrentThread.ManagedThreadId);
        };

        // Successful transaction - Begin + Commit
        Console.WriteLine("Demonstrating a successful transaction");

        // Initial task
        // Treated as "fire-and-forget" -- any exceptions will be cleaned up in rollback continuation
        Task tran1 = Task.Factory.StartNew(success);

        // The following task gets scheduled only if tran1 completes successfully
        var commitTran1 = tran1.ContinueWith(commit, TaskContinuationOptions.OnlyOnRanToCompletion);

        // The following task gets scheduled only if tran1 DOES NOT complete successfully
        var rollbackTran1 = tran1.ContinueWith(rollback, TaskContinuationOptions.NotOnRanToCompletion);

        // For demo purposes, wait for the sample to complete
        commitTran1.Wait();

        // -----------------------------------------------------------------------------------

        // Failed transaction - Begin + exception + Rollback
        Console.WriteLine("\nDemonstrating a failed transaction");

        // Initial task
        // Treated as "fire-and-forget" -- any exceptions will be cleaned up in rollback continuation
        Task tran2 = Task.Factory.StartNew(failure);

        // The following task gets scheduled only if tran2 completes successfully
        var commitTran2 = tran2.ContinueWith(commit, TaskContinuationOptions.OnlyOnRanToCompletion);

        // The following task gets scheduled only if tran2 DOES NOT complete successfully
        var rollbackTran2 = tran2.ContinueWith(rollback, TaskContinuationOptions.NotOnRanToCompletion);

        // For demo purposes, wait for the sample to complete
        rollbackTran2.Wait();
    }
}
open System
open System.Threading
open System.Threading.Tasks

// Demonstrated features:
//      TaskContinuationOptions
//		Task.ContinueWith()
// 		Task.Factory
//		Task.Wait()
// Expected results:
// 		This sample demonstrates branched continuation sequences - Task+Commit or Task+Rollback.
//      Notice that no if statements are used.
//		The first sequence is successful - tran1 and commitTran1 are executed. rollbackTran1 is canceled.
//		The second sequence is unsuccessful - tran2 and rollbackTran2 are executed. tran2 is faulted, and commitTran2 is canceled.
// Documentation:
//		http://msdn.microsoft.com/library/system.threading.tasks.taskcontinuationoptions(VS.100).aspx
let success =
    fun () ->
        printfn $"Task={Task.CurrentId}, Thread={Thread.CurrentThread.ManagedThreadId}: Begin successful transaction"

let failure =
    fun () ->

        printfn
            $"Task={Task.CurrentId}, Thread={Thread.CurrentThread.ManagedThreadId}: Begin transaction and encounter an error"

        raise (InvalidOperationException "SIMULATED EXCEPTION")

let commit =
    fun antecendent ->
        printfn $"Task={Task.CurrentId}, Thread={Thread.CurrentThread.ManagedThreadId}: Commit transaction"

let rollback =
    fun (antecendent: Task) ->

        // "Observe" your antecedent's exception so as to avoid an exception
        // being thrown on the finalizer thread
        let unused = antecendent.Exception

        printfn $"Task={Task.CurrentId}, Thread={Thread.CurrentThread.ManagedThreadId}: Rollback transaction"

// Successful transaction - Begin + Commit
printfn "Demonstrating a successful transaction"

// Initial task
// Treated as "fire-and-forget" -- any exceptions will be cleaned up in rollback continuation
let tran1 = Task.Factory.StartNew success

// The following task gets scheduled only if tran1 completes successfully
let commitTran1 =
    tran1.ContinueWith(commit, TaskContinuationOptions.OnlyOnRanToCompletion)

// The following task gets scheduled only if tran1 DOES NOT complete successfully
let rollbackTran1 =
    tran1.ContinueWith(rollback, TaskContinuationOptions.NotOnRanToCompletion)

// For demo purposes, wait for the sample to complete
commitTran1.Wait()

// -----------------------------------------------------------------------------------

// Failed transaction - Begin + exception + Rollback
printfn "\nDemonstrating a failed transaction"

// Initial task
// Treated as "fire-and-forget" -- any exceptions will be cleaned up in rollback continuation
let tran2: Task = Task.Factory.StartNew failure

// The following task gets scheduled only if tran2 completes successfully
let commitTran2 =
    tran2.ContinueWith(Action<Task> commit, TaskContinuationOptions.OnlyOnRanToCompletion)

// The following task gets scheduled only if tran2 DOES NOT complete successfully
let rollbackTran2 =
    tran2.ContinueWith(Action<Task> rollback, TaskContinuationOptions.NotOnRanToCompletion)

// For demo purposes, wait for the sample to complete
rollbackTran2.Wait()
Imports System.Threading
Imports System.Threading.Tasks

Module ContuationOptionsDemo
    ' Demonstrated features:
    '   TaskContinuationOptions
    '   Task.ContinueWith()
    '   Task.Factory
    '   Task.Wait()
    ' Expected results:
    '   This sample demonstrates branched continuation sequences - Task+Commit or Task+Rollback.
    '   Notice that no if statements are used.
    '   The first sequence is successful - tran1 and commitTran1 are executed. rollbackTran1 is canceled.
    '   The second sequence is unsuccessful - tran2 and rollbackTran2 are executed. tran2 is faulted, and commitTran2 is canceled.
    ' Documentation:
    '   http://msdn.microsoft.com/library/system.threading.tasks.taskcontinuationoptions(VS.100).aspx
    Private Sub Main()
        Dim success As Action = Sub()
                                    Console.WriteLine("Task={0}, Thread={1}: Begin successful transaction", Task.CurrentId, Thread.CurrentThread.ManagedThreadId)
                                End Sub

        Dim failure As Action = Sub()
                                    Console.WriteLine("Task={0}, Thread={1}: Begin transaction and encounter an error", Task.CurrentId, Thread.CurrentThread.ManagedThreadId)
                                    Throw New InvalidOperationException("SIMULATED EXCEPTION")
                                End Sub

        Dim commit As Action(Of Task) = Sub(antecendent)
                                            Console.WriteLine("Task={0}, Thread={1}: Commit transaction", Task.CurrentId, Thread.CurrentThread.ManagedThreadId)
                                        End Sub

        Dim rollback As Action(Of Task) = Sub(antecendent)
                                              ' "Observe" your antecedent's exception so as to avoid an exception
                                              ' being thrown on the finalizer thread
                                              Dim unused = antecendent.Exception

                                              Console.WriteLine("Task={0}, Thread={1}: Rollback transaction", Task.CurrentId, Thread.CurrentThread.ManagedThreadId)
                                          End Sub

        ' Successful transaction - Begin + Commit
        Console.WriteLine("Demonstrating a successful transaction")

        ' Initial task
        ' Treated as "fire-and-forget" -- any exceptions will be cleaned up in rollback continuation
        Dim tran1 As Task = Task.Factory.StartNew(success)

        ' The following task gets scheduled only if tran1 completes successfully
        Dim commitTran1 = tran1.ContinueWith(commit, TaskContinuationOptions.OnlyOnRanToCompletion)

        ' The following task gets scheduled only if tran1 DOES NOT complete successfully
        Dim rollbackTran1 = tran1.ContinueWith(rollback, TaskContinuationOptions.NotOnRanToCompletion)

        ' For demo purposes, wait for the sample to complete
        commitTran1.Wait()

        ' -----------------------------------------------------------------------------------


        ' Failed transaction - Begin + exception + Rollback 
        Console.WriteLine(vbLf & "Demonstrating a failed transaction")

        ' Initial task
        ' Treated as "fire-and-forget" -- any exceptions will be cleaned up in rollback continuation
        Dim tran2 As Task = Task.Factory.StartNew(failure)

        ' The following task gets scheduled only if tran2 completes successfully
        Dim commitTran2 = tran2.ContinueWith(commit, TaskContinuationOptions.OnlyOnRanToCompletion)

        ' The following task gets scheduled only if tran2 DOES NOT complete successfully
        Dim rollbackTran2 = tran2.ContinueWith(rollback, TaskContinuationOptions.NotOnRanToCompletion)

        ' For demo purposes, wait for the sample to complete
        rollbackTran2.Wait()
    End Sub
End Module

설명

반환 Task<TResult> 된 작업은 현재 작업이 완료될 때까지 실행 예약되지 않습니다. 매개 변수를 통해 continuationOptions 지정된 조건이 충족되지 않으면 연속 작업이 예약되지 않고 취소됩니다.

적용 대상

ContinueWith<TResult>(Func<Task,Object,TResult>, Object, TaskScheduler)

대상이 Task 완료되면 비동기적으로 실행되는 연속을 만듭니다. 연속은 호출자 제공 상태 정보를 수신하고 지정된 스케줄러를 사용합니다.

public:
generic <typename TResult>
 System::Threading::Tasks::Task<TResult> ^ ContinueWith(Func<System::Threading::Tasks::Task ^, System::Object ^, TResult> ^ continuationFunction, System::Object ^ state, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task<TResult> ContinueWith<TResult>(Func<System.Threading.Tasks.Task,object,TResult> continuationFunction, object state, System.Threading.Tasks.TaskScheduler scheduler);
member this.ContinueWith : Func<System.Threading.Tasks.Task, obj, 'Result> * obj * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWith(Of TResult) (continuationFunction As Func(Of Task, Object, TResult), state As Object, scheduler As TaskScheduler) As Task(Of TResult)

형식 매개 변수

TResult

연속으로 생성된 결과의 형식입니다.

매개 변수

continuationFunction
Func<Task,Object,TResult>

완료 시 실행할 Task 함수입니다. 실행하면 대리자가 완료된 작업과 호출자가 제공한 상태 개체를 인수로 전달합니다.

state
Object

연속 함수에서 사용할 데이터를 나타내는 개체입니다.

scheduler
TaskScheduler

TaskScheduler 연속 작업과 연결하고 해당 실행에 사용할 대상입니다.

반품

새 연속입니다 Task<TResult>.

예외

인수는 scheduler .입니다 null.

설명

반환 Task<TResult> 된 작업은 현재 작업이 완료될 때까지 실행이 완료되거나, 처리되지 않은 예외로 인해 오류가 발생하거나, 취소로 인해 일찍 종료될 때까지 실행되도록 예약되지 않습니다.

적용 대상

ContinueWith<TResult>(Func<Task,Object,TResult>, Object, CancellationToken)

대상이 Task 완료되고 값을 반환할 때 비동기적으로 실행되는 연속을 만듭니다. 연속은 호출자가 제공한 상태 정보 및 취소 토큰을 받습니다.

public:
generic <typename TResult>
 System::Threading::Tasks::Task<TResult> ^ ContinueWith(Func<System::Threading::Tasks::Task ^, System::Object ^, TResult> ^ continuationFunction, System::Object ^ state, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<TResult> ContinueWith<TResult>(Func<System.Threading.Tasks.Task,object,TResult> continuationFunction, object state, System.Threading.CancellationToken cancellationToken);
member this.ContinueWith : Func<System.Threading.Tasks.Task, obj, 'Result> * obj * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWith(Of TResult) (continuationFunction As Func(Of Task, Object, TResult), state As Object, cancellationToken As CancellationToken) As Task(Of TResult)

형식 매개 변수

TResult

연속으로 생성된 결과의 형식입니다.

매개 변수

continuationFunction
Func<Task,Object,TResult>

완료 시 실행할 Task 함수입니다. 실행하면 대리자가 완료된 작업과 호출자가 제공한 상태 개체를 인수로 전달합니다.

state
Object

연속 함수에서 사용할 데이터를 나타내는 개체입니다.

cancellationToken
CancellationToken

CancellationToken 새 연속 작업에 할당되는 작업입니다.

반품

새 연속입니다 Task<TResult>.

예외

인수는 continuationFunction .입니다 null.

제공된 CancellationToken 내용은 이미 삭제되었습니다.

설명

반환 Task<TResult> 된 작업은 현재 작업이 완료될 때까지 실행이 완료되거나, 처리되지 않은 예외로 인해 오류가 발생하거나, 취소로 인해 일찍 종료될 때까지 실행되도록 예약되지 않습니다.

적용 대상

ContinueWith<TResult>(Func<Task,Object,TResult>, Object)

호출자가 제공한 상태 정보를 수신하고 대상이 Task 완료되고 값을 반환할 때 비동기적으로 실행되는 연속을 만듭니다.

public:
generic <typename TResult>
 System::Threading::Tasks::Task<TResult> ^ ContinueWith(Func<System::Threading::Tasks::Task ^, System::Object ^, TResult> ^ continuationFunction, System::Object ^ state);
public System.Threading.Tasks.Task<TResult> ContinueWith<TResult>(Func<System.Threading.Tasks.Task,object,TResult> continuationFunction, object state);
member this.ContinueWith : Func<System.Threading.Tasks.Task, obj, 'Result> * obj -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWith(Of TResult) (continuationFunction As Func(Of Task, Object, TResult), state As Object) As Task(Of TResult)

형식 매개 변수

TResult

연속으로 생성된 결과의 형식입니다.

매개 변수

continuationFunction
Func<Task,Object,TResult>

완료 시 실행할 Task 함수입니다. 실행하면 대리자가 완료된 작업과 호출자가 제공한 상태 개체를 인수로 전달합니다.

state
Object

연속 함수에서 사용할 데이터를 나타내는 개체입니다.

반품

새 연속입니다 Task<TResult>.

예외

인수는 continuationFunction .입니다 null.

설명

반환 Task<TResult> 된 작업은 현재 작업이 완료될 때까지 실행이 완료되거나, 처리되지 않은 예외로 인해 오류가 발생하거나, 취소로 인해 일찍 종료될 때까지 실행되도록 예약되지 않습니다.

적용 대상

ContinueWith<TResult>(Func<Task,TResult>, TaskContinuationOptions)

지정된 연속 옵션에 따라 실행되는 연속 작업을 만들고 값을 반환합니다.

public:
generic <typename TResult>
 System::Threading::Tasks::Task<TResult> ^ ContinueWith(Func<System::Threading::Tasks::Task ^, TResult> ^ continuationFunction, System::Threading::Tasks::TaskContinuationOptions continuationOptions);
public System.Threading.Tasks.Task<TResult> ContinueWith<TResult>(Func<System.Threading.Tasks.Task,TResult> continuationFunction, System.Threading.Tasks.TaskContinuationOptions continuationOptions);
member this.ContinueWith : Func<System.Threading.Tasks.Task, 'Result> * System.Threading.Tasks.TaskContinuationOptions -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWith(Of TResult) (continuationFunction As Func(Of Task, TResult), continuationOptions As TaskContinuationOptions) As Task(Of TResult)

형식 매개 변수

TResult

연속으로 생성된 결과의 형식입니다.

매개 변수

continuationFunction
Func<Task,TResult>

에 지정된 조건에 따라 실행할 함수입니다 continuationOptions. 실행하면 대리자가 완료된 작업을 인수로 전달합니다.

continuationOptions
TaskContinuationOptions

연속 작업이 예약된 시기 및 동작 방식에 대한 옵션입니다. 여기에는 조건(예: OnlyOnCanceled.)과 같은 실행 옵션이 ExecuteSynchronously포함됩니다.

반품

새 연속입니다 Task<TResult>.

예외

Task 삭제되었습니다.

인수가 continuationFunction null입니다.

인수가 continuationOptions 잘못된 값을 TaskContinuationOptions지정합니다.

설명

반환 Task<TResult> 된 작업은 현재 작업이 완료될 때까지 실행 예약되지 않습니다. 매개 변수를 통해 continuationOptions 지정된 연속 조건이 충족되지 않으면 연속 작업이 예약되지 않고 취소됩니다.

적용 대상

ContinueWith<TResult>(Func<Task,TResult>, CancellationToken)

대상이 Task 완료되고 값을 반환할 때 비동기적으로 실행되는 연속을 만듭니다. 연속은 취소 토큰을 받습니다.

public:
generic <typename TResult>
 System::Threading::Tasks::Task<TResult> ^ ContinueWith(Func<System::Threading::Tasks::Task ^, TResult> ^ continuationFunction, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<TResult> ContinueWith<TResult>(Func<System.Threading.Tasks.Task,TResult> continuationFunction, System.Threading.CancellationToken cancellationToken);
member this.ContinueWith : Func<System.Threading.Tasks.Task, 'Result> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWith(Of TResult) (continuationFunction As Func(Of Task, TResult), cancellationToken As CancellationToken) As Task(Of TResult)

형식 매개 변수

TResult

연속으로 생성된 결과의 형식입니다.

매개 변수

continuationFunction
Func<Task,TResult>

완료 시 실행할 Task 함수입니다. 실행하면 대리자가 완료된 작업을 인수로 전달합니다.

cancellationToken
CancellationToken

CancellationToken 새 연속 작업에 할당되는 작업입니다.

반품

새 연속입니다 Task<TResult>.

예외

Task 삭제되었습니다.

-또는-

CancellationTokenSource 토큰을 만든 토큰이 이미 삭제되었습니다.

인수가 continuationFunction null입니다.

설명

반환 Task<TResult> 된 작업은 현재 작업이 완료될 때까지 실행이 완료되거나, 처리되지 않은 예외로 인해 오류가 발생하거나, 취소로 인해 일찍 종료될 때까지 실행되도록 예약되지 않습니다.

적용 대상

ContinueWith<TResult>(Func<Task,TResult>)

대상이 Task<TResult> 완료되고 값을 반환할 때 비동기적으로 실행되는 연속을 만듭니다.

public:
generic <typename TResult>
 System::Threading::Tasks::Task<TResult> ^ ContinueWith(Func<System::Threading::Tasks::Task ^, TResult> ^ continuationFunction);
public System.Threading.Tasks.Task<TResult> ContinueWith<TResult>(Func<System.Threading.Tasks.Task,TResult> continuationFunction);
member this.ContinueWith : Func<System.Threading.Tasks.Task, 'Result> -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWith(Of TResult) (continuationFunction As Func(Of Task, TResult)) As Task(Of TResult)

형식 매개 변수

TResult

연속으로 생성된 결과의 형식입니다.

매개 변수

continuationFunction
Func<Task,TResult>

완료 시 실행할 Task<TResult> 함수입니다. 실행하면 대리자가 완료된 작업을 인수로 전달합니다.

반품

새 연속 작업입니다.

예외

Task 삭제되었습니다.

인수가 continuationFunction null입니다.

예제

다음 예제에서는 ContinueWith 메서드를 사용하는 방법을 보여줍니다.

using System;
using System.Threading;
using System.Threading.Tasks;

class ContinuationSimpleDemo
{
    // Demonstrated features:
    // 		Task.Factory
    //		Task.ContinueWith()
    //		Task.Wait()
    // Expected results:
    // 		A sequence of three unrelated tasks is created and executed in this order - alpha, beta, gamma.
    //		A sequence of three related tasks is created - each task negates its argument and passes is to the next task: 5, -5, 5 is printed.
    //		A sequence of three unrelated tasks is created where tasks have different types.
    // Documentation:
    //		http://msdn.microsoft.com/library/system.threading.tasks.taskfactory_members(VS.100).aspx
    static void Main()
    {
        Action<string> action =
            (str) =>
                Console.WriteLine("Task={0}, str={1}, Thread={2}", Task.CurrentId, str, Thread.CurrentThread.ManagedThreadId);

        // Creating a sequence of action tasks (that return no result).
        Console.WriteLine("Creating a sequence of action tasks (that return no result)");
        Task.Factory.StartNew(() => action("alpha"))
            .ContinueWith(antecendent => action("beta"))        // Antecedent data is ignored
            .ContinueWith(antecendent => action("gamma"))
            .Wait();

        Func<int, int> negate =
            (n) =>
            {
                Console.WriteLine("Task={0}, n={1}, -n={2}, Thread={3}", Task.CurrentId, n, -n, Thread.CurrentThread.ManagedThreadId);
                return -n;
            };

        // Creating a sequence of function tasks where each continuation uses the result from its antecendent
        Console.WriteLine("\nCreating a sequence of function tasks where each continuation uses the result from its antecendent");
        Task<int>.Factory.StartNew(() => negate(5))
            .ContinueWith(antecendent => negate(antecendent.Result))		// Antecedent result feeds into continuation
            .ContinueWith(antecendent => negate(antecendent.Result))
            .Wait();

        // Creating a sequence of tasks where you can mix and match the types
        Console.WriteLine("\nCreating a sequence of tasks where you can mix and match the types");
        Task<int>.Factory.StartNew(() => negate(6))
            .ContinueWith(antecendent => action("x"))
            .ContinueWith(antecendent => negate(7))
            .Wait();
    }
}
open System
open System.Threading
open System.Threading.Tasks

// Demonstrated features:
// 		Task.Factory
//		Task.ContinueWith()
//		Task.Wait()
// Expected results:
// 		A sequence of three unrelated tasks is created and executed in this order - alpha, beta, gamma.
//		A sequence of three related tasks is created - each task negates its argument and passes is to the next task: 5, -5, 5 is printed.
//		A sequence of three unrelated tasks is created where tasks have different types.
// Documentation:
//		http://msdn.microsoft.com/library/system.threading.tasks.taskfactory_members(VS.100).aspx
let action =
    fun str -> printfn $"Task={Task.CurrentId}, str=%s{str}, Thread={Thread.CurrentThread.ManagedThreadId}"

// Creating a sequence of action tasks (that return no result).
printfn "Creating a sequence of action tasks (that return no result)"

Task
    .Factory
    .StartNew(fun () -> action "alpha")
    .ContinueWith(fun antecendent -> action "beta") // Antecedent data is ignored
    .ContinueWith(fun antecendent -> action "gamma")
    .Wait()

let negate =
    fun n ->
        printfn $"Task={Task.CurrentId}, n={n}, -n={2 - n}, Thread={Thread.CurrentThread.ManagedThreadId}"
        -n

// Creating a sequence of function tasks where each continuation uses the result from its antecendent
printfn "\nCreating a sequence of function tasks where each continuation uses the result from its antecendent"

Task<int>
    .Factory.StartNew(fun () -> negate 5)
    .ContinueWith(Func<Task<int>, int>(fun antecedent -> negate antecedent.Result)) // Antecedent result feeds into continuation
    .ContinueWith(Func<Task<int>, int>(fun antecedent -> negate antecedent.Result))
    .Wait()

// Creating a sequence of tasks where you can mix and match the types
printfn "\nCreating a sequence of tasks where you can mix and match the types"

Task<int>
    .Factory.StartNew(fun () -> negate 6)
    .ContinueWith(Action<Task>(fun antecendent -> action "x"))
    .ContinueWith(fun antecendent -> negate 7)
    .Wait()
Imports System.Threading
Imports System.Threading.Tasks

Module ContinuationDemo

    ' Demonstrated features:
    '   Task.Factory
    '   Task.ContinueWith()
    '   Task.Wait()
    ' Expected results:
    '   A sequence of three unrelated tasks is created and executed in this order - alpha, beta, gamma.
    '   A sequence of three related tasks is created - each task negates its argument and passes is to the next task: 5, -5, 5 is printed.
    '   A sequence of three unrelated tasks is created where tasks have different types.
    ' Documentation:
    '   http://msdn.microsoft.com/library/system.threading.tasks.taskfactory_members(VS.100).aspx
    Sub Main()
        Dim action As Action(Of String) = Sub(str) Console.WriteLine("Task={0}, str={1}, Thread={2}", Task.CurrentId, str, Thread.CurrentThread.ManagedThreadId)

        ' Creating a sequence of action tasks (that return no result).
        Console.WriteLine("Creating a sequence of action tasks (that return no result)")
        ' Continuations ignore antecedent data
        Task.Factory.StartNew(Sub() action("alpha")).ContinueWith(Sub(antecendent) action("beta")).ContinueWith(Sub(antecendent) action("gamma")).Wait()


        Dim negate As Func(Of Integer, Integer) = Function(n)
                                                      Console.WriteLine("Task={0}, n={1}, -n={2}, Thread={3}", Task.CurrentId, n, -n, Thread.CurrentThread.ManagedThreadId)
                                                      Return -n
                                                  End Function

        ' Creating a sequence of function tasks where each continuation uses the result from its antecendent
        Console.WriteLine(vbLf & "Creating a sequence of function tasks where each continuation uses the result from its antecendent")
        Task(Of Integer).Factory.StartNew(Function() negate(5)).ContinueWith(Function(antecendent) negate(antecendent.Result)).ContinueWith(Function(antecendent) negate(antecendent.Result)).Wait()


        ' Creating a sequence of tasks where you can mix and match the types
        Console.WriteLine(vbLf & "Creating a sequence of tasks where you can mix and match the types")
        Task(Of Integer).Factory.StartNew(Function() negate(6)).ContinueWith(Sub(antecendent) action("x")).ContinueWith(Function(antecendent) negate(7)).Wait()
    End Sub
End Module

설명

반환 Task<TResult> 된 작업은 현재 작업이 완료될 때까지 실행이 완료되거나, 처리되지 않은 예외로 인해 오류가 발생하거나, 취소로 인해 일찍 종료될 때까지 실행되도록 예약되지 않습니다.

적용 대상

ContinueWith<TResult>(Func<Task,TResult>, TaskScheduler)

대상이 Task 완료되고 값을 반환할 때 비동기적으로 실행되는 연속을 만듭니다. 연속 작업은 지정된 스케줄러를 사용합니다.

public:
generic <typename TResult>
 System::Threading::Tasks::Task<TResult> ^ ContinueWith(Func<System::Threading::Tasks::Task ^, TResult> ^ continuationFunction, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task<TResult> ContinueWith<TResult>(Func<System.Threading.Tasks.Task,TResult> continuationFunction, System.Threading.Tasks.TaskScheduler scheduler);
member this.ContinueWith : Func<System.Threading.Tasks.Task, 'Result> * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task<'Result>
Public Function ContinueWith(Of TResult) (continuationFunction As Func(Of Task, TResult), scheduler As TaskScheduler) As Task(Of TResult)

형식 매개 변수

TResult

연속으로 생성된 결과의 형식입니다.

매개 변수

continuationFunction
Func<Task,TResult>

완료 시 실행할 Task 함수입니다. 실행하면 대리자가 완료된 작업을 인수로 전달합니다.

scheduler
TaskScheduler

TaskScheduler 연속 작업과 연결하고 해당 실행에 사용할 대상입니다.

반품

새 연속입니다 Task<TResult>.

예외

Task 삭제되었습니다.

인수가 continuationFunction null입니다.

-또는-

인수가 scheduler null입니다.

설명

반환 Task<TResult> 된 작업은 현재 작업이 완료될 때까지 실행이 완료되거나, 처리되지 않은 예외로 인해 오류가 발생하거나, 취소로 인해 일찍 종료될 때까지 실행되도록 예약되지 않습니다.

적용 대상