Task<TResult>.ContinueWith 메서드

정의

다른 작업이 완료될 때 실행되는 연속 작업을 만듭니다.Creates a continuation task that executes when another task completes.

오버로드

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

대상 Task<TResult>이 완료될 때 실행되는 연속 작업을 만듭니다.Creates a continuation that executes when the target Task<TResult> completes.

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

continuationOptions에 지정된 조건에 따라 실행되는 연속 작업을 만듭니다.Creates a continuation that executes according the condition specified in continuationOptions.

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

대상 Task<TResult>이 완료될 때 실행되는 연속 작업을 만듭니다.Creates a continuation that executes when the target Task<TResult> completes.

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

대상 Task<TResult>이 완료될 때 실행되는 연속 작업을 만듭니다.Creates a continuation that executes when the target Task<TResult> completes.

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

대상 Task<TResult>이 완료될 때 실행되는 연속 작업을 만듭니다.Creates a continuation that executes when the target Task<TResult> completes.

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

continuationOptions에 지정된 조건에 따라 실행되는 연속 작업을 만듭니다.Creates a continuation that executes according the condition specified in continuationOptions.

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

대상 Task<TResult>이 완료될 때 비동기적으로 실행되는 취소 가능 연속 작업을 만듭니다.Creates a cancelable continuation that executes asynchronously when the target Task<TResult> completes.

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

상태 정보가 전달되며 대상 Task<TResult>이 완료되면 실행되는 연속 작업을 만듭니다.Creates a continuation that is passed state information and that executes when the target Task<TResult> completes.

ContinueWith(Action<Task<TResult>>)

대상 작업이 완료될 때 비동기적으로 실행되는 연속 작업을 만듭니다.Creates a continuation that executes asynchronously when the target task completes.

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

대상 Task<TResult>가 완료될 때 비동기적으로 실행되는 연속 작업을 만듭니다.Creates a continuation that executes asynchronously when the target Task<TResult> completes.

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

대상 Task<TResult>이 완료될 때 실행되는 연속 작업을 만듭니다.Creates a continuation that executes when the target Task<TResult> completes.

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

continuationOptions에 지정된 조건에 따라 실행되는 연속 작업을 만듭니다.Creates a continuation that executes according the condition specified in continuationOptions.

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

대상 Task<TResult>이 완료될 때 실행되는 연속 작업을 만듭니다.Creates a continuation that executes when the target Task<TResult> completes.

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

대상 Task<TResult>이 완료될 때 실행되는 연속 작업을 만듭니다.Creates a continuation that executes when the target Task<TResult> completes.

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

대상 Task<TResult>이 완료될 때 실행되는 연속 작업을 만듭니다.Creates a continuation that executes when the target Task<TResult> completes.

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

continuationOptions에 지정된 조건에 따라 실행되는 연속 작업을 만듭니다.Creates a continuation that executes according the condition specified in continuationOptions.

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

대상 Task<TResult>가 완료될 때 비동기적으로 실행되는 연속 작업을 만듭니다.Creates a continuation that executes asynchronously when the target Task<TResult> completes.

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

대상 Task<TResult>이 완료될 때 실행되는 연속 작업을 만듭니다.Creates a continuation that executes when the target Task<TResult> completes.

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

대상 Task<TResult>가 완료될 때 비동기적으로 실행되는 연속 작업을 만듭니다.Creates a continuation that executes asynchronously when the target Task<TResult> completes.

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

대상 Task<TResult>가 완료될 때 비동기적으로 실행되는 연속 작업을 만듭니다.Creates a continuation that executes asynchronously when the target Task<TResult> completes.

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

대상 Task<TResult>이 완료될 때 실행되는 연속 작업을 만듭니다.Creates a continuation that executes when the target Task<TResult> completes.

public:
 System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task<TResult> ^, 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<TResult>,object> continuationAction, object state, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);
override this.ContinueWith : Action<System.Threading.Tasks.Task<'Result>, obj> * obj * System.Threading.CancellationToken * System.Threading.Tasks.TaskContinuationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task

매개 변수

continuationAction
Action<Task<TResult>,Object>

Task<TResult>이 완료될 때 실행할 동작입니다.An action to run when the Task<TResult> completes. 실행되는 경우 대리자에게 완료된 작업과 호출자 제공 상태 개체가 인수로 전달됩니다.When run, the delegate will be passed the completed task and the caller-supplied state object as arguments.

state
Object

연속 동작에서 사용할 데이터를 나타내는 개체입니다.An object representing data to be used by the continuation action.

cancellationToken
CancellationToken

새 연속 작업에 할당할 CancellationToken입니다.The CancellationToken that will be assigned to the new continuation task.

continuationOptions
TaskContinuationOptions

연속 작업이 예약되는 시기와 연속 작업이 동작하는 방식에 대한 옵션입니다.Options for when the continuation is scheduled and how it behaves. 여기에는 OnlyOnCanceled와 같은 조건과 ExecuteSynchronously 등의 실행 옵션이 포함됩니다.This includes criteria, such as OnlyOnCanceled, as well as execution options, such as ExecuteSynchronously.

scheduler
TaskScheduler

연속 작업과 연결하고 연속 작업의 실행에 사용할 TaskScheduler입니다.The TaskScheduler to associate with the continuation task and to use for its execution.

반환

새 연속 Task입니다.A new continuation Task.

예외

scheduler 인수가 null인 경우The scheduler argument is null.

continuationOptions 인수는 TaskContinuationOptions에 대해 잘못된 값을 지정합니다.The continuationOptions argument specifies an invalid value for TaskContinuationOptions.

제공된 CancellationToken가 이미 삭제된 경우The provided CancellationToken has already been disposed.

설명

반환 된 Task는 현재 작업이 완료 될 때까지 실행 하도록 예약 되지 않습니다.The returned Task will not be scheduled for execution until the current task has completed. continuationOptions 매개 변수를 통해 지정 된 조건이 충족 되지 않으면 예약 된 대신 연속 작업이 취소 됩니다.If the criteria specified through the continuationOptions parameter are not met, the continuation task will be canceled instead of scheduled.

추가 정보

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

continuationOptions에 지정된 조건에 따라 실행되는 연속 작업을 만듭니다.Creates a continuation that executes according the condition specified in continuationOptions.

public:
 System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task<TResult> ^> ^ 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<TResult>> continuationAction, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);
override this.ContinueWith : Action<System.Threading.Tasks.Task<'Result>> * System.Threading.CancellationToken * System.Threading.Tasks.TaskContinuationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task

매개 변수

continuationAction
Action<Task<TResult>>

continuationOptions에 지정된 조건에 따라 실행되는 작업입니다.An action to run according the condition specified in continuationOptions. 실행될 때 이 대리자에는 완료된 작업이 인수로 전달됩니다.When run, the delegate will be passed the completed task as an argument.

cancellationToken
CancellationToken

새 연속 작업에 할당할 CancellationToken입니다.The CancellationToken that will be assigned to the new continuation task.

continuationOptions
TaskContinuationOptions

연속 작업이 예약되는 시기와 연속 작업이 동작하는 방식에 대한 옵션입니다.Options for when the continuation is scheduled and how it behaves. 여기에는 OnlyOnCanceled와 같은 조건과 ExecuteSynchronously 등의 실행 옵션이 포함됩니다.This includes criteria, such as OnlyOnCanceled, as well as execution options, such as ExecuteSynchronously.

scheduler
TaskScheduler

연속 작업과 연결하고 연속 작업의 실행에 사용할 TaskScheduler입니다.The TaskScheduler to associate with the continuation task and to use for its execution.

반환

새 연속 Task입니다.A new continuation Task.

예외

Task<TResult>가 삭제된 경우The Task<TResult> has been disposed.

또는-or- cancellationToken을 만든 CancellationTokenSource가 이미 삭제되었습니다.The CancellationTokenSource that created cancellationToken has already been disposed.

continuationAction 인수가 null인 경우The continuationAction argument is null.

또는-or- scheduler 인수가 null인 경우The scheduler argument is null.

continuationOptions 인수는 TaskContinuationOptions에 대해 잘못된 값을 지정합니다.The continuationOptions argument specifies an invalid value for TaskContinuationOptions.

설명

반환 된 Task는 현재 작업이 완료 될 때까지 실행 하도록 예약 되지 않습니다.The returned Task will not be scheduled for execution until the current task has completed. continuationOptions 매개 변수를 통해 지정 된 조건이 충족 되지 않으면 예약 된 대신 연속 작업이 취소 됩니다.If the criteria specified through the continuationOptions parameter are not met, the continuation task will be canceled instead of scheduled. 자세한 내용은 연속 작업을 사용하여 작업 연결을 참조하세요.For more information, see Chaining Tasks by Using Continuation Tasks.

추가 정보

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

대상 Task<TResult>이 완료될 때 실행되는 연속 작업을 만듭니다.Creates a continuation that executes when the target Task<TResult> completes.

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

매개 변수

continuationAction
Action<Task<TResult>,Object>

Task<TResult>이 완료될 때 실행할 동작입니다.An action to run when the Task<TResult> completes. 실행되는 경우 대리자에게 완료된 작업과 호출자 제공 상태 개체가 인수로 전달됩니다.When run, the delegate will be passed the completed task and the caller-supplied state object as arguments.

state
Object

연속 동작에서 사용할 데이터를 나타내는 개체입니다.An object representing data to be used by the continuation action.

scheduler
TaskScheduler

연속 작업과 연결하고 연속 작업의 실행에 사용할 TaskScheduler입니다.The TaskScheduler to associate with the continuation task and to use for its execution.

반환

새 연속 Task입니다.A new continuation Task.

예외

scheduler 인수가 null인 경우The scheduler argument is null.

설명

반환 된 Task는 현재 작업이 완료 될 때까지 실행 되도록 예약 되지 않습니다. 완료 될 때까지 실행 되거나, 처리 되지 않은 예외로 인해 오류가 발생 했거나, 취소 되어 초기에 종료 될 때까지 실행이 예약 되지 않습니다.The returned Task will not be scheduled for execution until the current task has completed, whether it completes due to running to completion successfully, faulting due to an unhandled exception, or exiting out early due to being canceled.

추가 정보

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

대상 Task<TResult>이 완료될 때 실행되는 연속 작업을 만듭니다.Creates a continuation that executes when the target Task<TResult> completes.

public:
 System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task<TResult> ^, System::Object ^> ^ continuationAction, System::Object ^ state, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task ContinueWith (Action<System.Threading.Tasks.Task<TResult>,object> continuationAction, object state, System.Threading.CancellationToken cancellationToken);
override this.ContinueWith : Action<System.Threading.Tasks.Task<'Result>, obj> * obj * System.Threading.CancellationToken -> System.Threading.Tasks.Task

매개 변수

continuationAction
Action<Task<TResult>,Object>

Task<TResult>이 완료될 때 실행할 동작입니다.An action to run when the Task<TResult> completes. 실행되는 경우 대리자에게 완료된 작업과 호출자 제공 상태 개체가 인수로 전달됩니다.When run, the delegate will be passed the completed task and the caller-supplied state object as arguments.

state
Object

연속 동작에서 사용할 데이터를 나타내는 개체입니다.An object representing data to be used by the continuation action.

cancellationToken
CancellationToken

새 연속 작업에 할당할 CancellationToken입니다.The CancellationToken that will be assigned to the new continuation task.

반환

새 연속 Task입니다.A new continuation Task.

예외

continuationAction 인수가 null인 경우The continuationAction argument is null.

제공된 CancellationToken가 이미 삭제된 경우The provided CancellationToken has already been disposed.

설명

반환 된 Task는 현재 작업이 완료 될 때까지 실행 되도록 예약 되지 않습니다. 완료 될 때까지 실행 되거나, 처리 되지 않은 예외로 인해 오류가 발생 했거나, 취소 되어 초기에 종료 될 때까지 실행이 예약 되지 않습니다.The returned Task will not be scheduled for execution until the current task has completed, whether it completes due to running to completion successfully, faulting due to an unhandled exception, or exiting out early due to being canceled.

추가 정보

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

대상 Task<TResult>이 완료될 때 실행되는 연속 작업을 만듭니다.Creates a continuation that executes when the target Task<TResult> completes.

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

매개 변수

continuationAction
Action<Task<TResult>,Object>

Task<TResult>이 완료될 때 실행할 동작입니다.An action to run when the Task<TResult> completes. 실행되는 경우 대리자에게 완료된 작업과 호출자 제공 상태 개체가 인수로 전달됩니다.When run, the delegate will be passed the completed task and the caller-supplied state object as arguments.

state
Object

연속 동작에서 사용할 데이터를 나타내는 개체입니다.An object representing data to be used by the continuation action.

continuationOptions
TaskContinuationOptions

연속 작업이 예약되는 시기와 연속 작업이 동작하는 방식에 대한 옵션입니다.Options for when the continuation is scheduled and how it behaves. 여기에는 OnlyOnCanceled와 같은 조건과 ExecuteSynchronously 등의 실행 옵션이 포함됩니다.This includes criteria, such as OnlyOnCanceled, as well as execution options, such as ExecuteSynchronously.

반환

새 연속 Task입니다.A new continuation Task.

예외

continuationAction 인수가 null인 경우The continuationAction argument is null.

continuationOptions 인수는 TaskContinuationOptions에 대해 잘못된 값을 지정합니다.The continuationOptions argument specifies an invalid value for TaskContinuationOptions.

설명

반환 된 Task는 현재 작업이 완료 될 때까지 실행 하도록 예약 되지 않습니다.The returned Task will not be scheduled for execution until the current task has completed. continuationOptions 매개 변수를 통해 지정 된 연속 조건이 충족 되지 않으면 예약 된 대신 연속 작업이 취소 됩니다.If the continuation criteria specified through the continuationOptions parameter are not met, the continuation task will be canceled instead of scheduled.

추가 정보

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

continuationOptions에 지정된 조건에 따라 실행되는 연속 작업을 만듭니다.Creates a continuation that executes according the condition specified in continuationOptions.

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

매개 변수

continuationAction
Action<Task<TResult>>

continuationOptions에 지정된 조건에 따른 작업입니다.An action to according the condition specified in continuationOptions. 실행될 때 이 대리자에는 완료된 작업이 인수로 전달됩니다.When run, the delegate will be passed the completed task as an argument.

continuationOptions
TaskContinuationOptions

연속 작업이 예약되는 시기와 연속 작업이 동작하는 방식에 대한 옵션입니다.Options for when the continuation is scheduled and how it behaves. 여기에는 OnlyOnCanceled와 같은 조건과 ExecuteSynchronously 등의 실행 옵션이 포함됩니다.This includes criteria, such as OnlyOnCanceled, as well as execution options, such as ExecuteSynchronously.

반환

새 연속 Task입니다.A new continuation Task.

예외

Task<TResult>가 삭제된 경우The Task<TResult> has been disposed.

continuationAction 인수가 null인 경우The continuationAction argument is null.

continuationOptions 인수는 TaskContinuationOptions에 대해 잘못된 값을 지정합니다.The continuationOptions argument specifies an invalid value for TaskContinuationOptions.

설명

반환 된 Task는 현재 작업이 완료 될 때까지 실행 하도록 예약 되지 않습니다.The returned Task will not be scheduled for execution until the current task has completed. continuationOptions 매개 변수를 통해 지정 된 연속 조건이 충족 되지 않으면 예약 된 대신 연속 작업이 취소 됩니다.If the continuation criteria specified through the continuationOptions parameter are not met, the continuation task will be canceled instead of scheduled.

자세한 내용은 연속 작업을 사용하여 작업 연결을 참조하세요.For more information, see Chaining Tasks by Using Continuation Tasks.

추가 정보

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

대상 Task<TResult>이 완료될 때 비동기적으로 실행되는 취소 가능 연속 작업을 만듭니다.Creates a cancelable continuation that executes asynchronously when the target Task<TResult> completes.

public:
 System::Threading::Tasks::Task ^ ContinueWith(Action<System::Threading::Tasks::Task<TResult> ^> ^ continuationAction, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task ContinueWith (Action<System.Threading.Tasks.Task<TResult>> continuationAction, System.Threading.CancellationToken cancellationToken);
override this.ContinueWith : Action<System.Threading.Tasks.Task<'Result>> * System.Threading.CancellationToken -> System.Threading.Tasks.Task

매개 변수

continuationAction
Action<Task<TResult>>

Task<TResult>이 완료될 때 실행할 동작입니다.An action to run when the Task<TResult> completes. 실행될 때 이 대리자에는 완료된 작업이 인수로 전달됩니다.When run, the delegate is passed the completed task as an argument.

cancellationToken
CancellationToken

새 연속 작업에 전달되는 취소 토큰입니다.The cancellation token that is passed to the new continuation task.

반환

새 연속 작업입니다.A new continuation task.

예외

Task<TResult>가 삭제된 경우The Task<TResult> has been disposed.

또는-or- cancellationToken을 만든 CancellationTokenSource가 삭제되었습니다.The CancellationTokenSource that created cancellationToken has been disposed.

continuationAction 인수가 null인 경우The continuationAction argument is null.

예제

다음 예제에서는 에라토스테네스의 체를 사용 하 여 사용자가 입력 한 값 1 사이의 소수를 계산 하는 선행 태스크를 만듭니다.The following example creates an antecedent task that uses the Sieve of Eratosthenes to calculate the prime numbers between 1 and a value entered by the user. 소수에 대 한 정보를 저장 하는 배열을 사용 됩니다.An array is used to hold information about the prime numbers. 배열 인덱스는 숫자를 나타내고, 요소의 값은 해당 숫자가 복합 형식 인지 (값 true) 또는 소수 (값은 false)를 나타냅니다.The array index represents the number, and the element's value indicates whether that number is composite (its value is true) or prime (its value is false). 그러면이 태스크는 정수 배열에서 소수를 추출 하 고 표시 하는 일을 담당 하는 연속 작업에 전달 됩니다.This task is then passed to a continuation task, which is responsible for extracting the prime numbers from the integer array and displaying them.

취소 토큰은 선행 작업 및 연속 작업에 전달 됩니다.A cancellation token is passed to both the antecedent and the continuation task. System.Timers.Timer 개체는 100 밀리초의 제한 시간 값을 정의 하는 데 사용 됩니다.A System.Timers.Timer object is used to define a timeout value of 100 milliseconds. 이벤트가 발생 하면 CancellationTokenSource.Cancel 메서드가 호출 되 고 취소 토큰이 작업 취소를 요청 하는 데 사용 됩니다.If the event fires, the CancellationTokenSource.Cancel method is called, and the cancellation token is used to request cancellation of the tasks.

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Timers = System.Timers;

public class Example
{
   static CancellationTokenSource ts;
   
   public static void Main(string[] args)
   {
      int upperBound = args.Length >= 1 ? Int32.Parse(args[0]) : 200;
      ts = new CancellationTokenSource();
      CancellationToken token = ts.Token;
      Timers.Timer timer = new Timers.Timer(3000);
      timer.Elapsed += TimedOutEvent;
      timer.AutoReset = false;
      timer.Enabled = true;

      var t1 = Task.Run(() => { // True = composite.
                                // False = prime.
                                bool[] values = new bool[upperBound + 1];
                                for (int ctr = 2; ctr <= (int) Math.Sqrt(upperBound); ctr++) {
                                   if (values[ctr] == false) {
                                      for (int product = ctr * ctr; product <= upperBound;
                                                                    product = product + ctr)
                                         values[product] = true;
                                   }
                                   token.ThrowIfCancellationRequested();
                                }
                                return values; }, token);

      var t2 = t1.ContinueWith( (antecedent) => { // Create a list of prime numbers.
                                                  var  primes = new List<int>();
                                                  token.ThrowIfCancellationRequested();
                                                  bool[] numbers = antecedent.Result;
                                                  string output = String.Empty;

                                                  for (int ctr = 1; ctr <= numbers.GetUpperBound(0); ctr++)
                                                     if (numbers[ctr] == false)
                                                        primes.Add(ctr);

                                                  // Create the output string.
                                                  for (int ctr = 0; ctr < primes.Count; ctr++) {
                                                     token.ThrowIfCancellationRequested();
                                                     output += primes[ctr].ToString("N0");
                                                     if (ctr < primes.Count - 1)
                                                        output += ",  ";
                                                     if ((ctr + 1) % 8 == 0)
                                                        output += Environment.NewLine;
                                                  }
                                                  //Display the result.
                                                  Console.WriteLine("Prime numbers from 1 to {0}:\n",
                                                                    upperBound);
                                                  Console.WriteLine(output);
                                                }, token);
      try {
         t2.Wait();
      }
      catch (AggregateException ae) {
         foreach (var e in ae.InnerExceptions) {
            if (e.GetType() == typeof(TaskCanceledException))
               Console.WriteLine("The operation was cancelled.");
            else
               Console.WriteLine("ELSE: {0}: {1}", e.GetType().Name, e.Message);
         }
      }
      finally {
         ts.Dispose();
      }
   }

   private static void TimedOutEvent(Object source, Timers.ElapsedEventArgs e)
   {
      ts.Cancel();
   }
}
// If cancellation is not requested, the example displays output like the following:
//       Prime numbers from 1 to 400:
//
//       1,  2,  3,  5,  7,  11,  13,  17,
//       19,  23,  29,  31,  37,  41,  43,  47,
//       53,  59,  61,  67,  71,  73,  79,  83,
//       89,  97,  101,  103,  107,  109,  113,  127,
//       131,  137,  139,  149,  151,  157,  163,  167,
//       173,  179,  181,  191,  193,  197,  199,  211,
//       223,  227,  229,  233,  239,  241,  251,  257,
//       263,  269,  271,  277,  281,  283,  293,  307,
//       311,  313,  317,  331,  337,  347,  349,  353,
//       359,  367,  373,  379,  383,  389,  397,  401
// If cancellation is requested, the example displays output like the following:
//       The operation was cancelled.
Imports System.Collections.Generic
Imports System.Threading
Imports System.Threading.Tasks
Imports Timers = System.Timers

Module Example
   Dim ts As CancellationTokenSource

   Public Sub Main(args() As String)
      Dim upperBound As Integer = If(args.Length >= 1, CInt(args(0)), 200)
      ts = New CancellationTokenSource()
      Dim token As CancellationToken = ts.Token
      Dim timer As New Timers.Timer(100)
      AddHandler timer.Elapsed, AddressOf TimedOutEvent
      timer.AutoReset = False
      timer.Enabled = True

      Dim t1 = Task.Run(Function()
                          ' True = composite.
                          ' False = prime.
                          Dim values(upperBound) As Boolean
                          For ctr = 2 To CInt(Math.Sqrt(upperBound))
                             If values(ctr) = False Then
                                For product = ctr * ctr To upperBound Step ctr
                                   values(product) = True
                                Next
                             End If
                             token.ThrowIfCancellationRequested()
                          Next
                          Return values
                       End Function, token)

      Dim t2 = t1.ContinueWith(Sub(antecedent)
                                  ' Create a list of prime numbers.
                                  Dim primes As New List(Of Integer)()
                                  token.ThrowIfCancellationRequested()
                                  Dim numbers As Boolean() = antecedent.Result
                                  Dim output As String = String.Empty
                                  
                                  For ctr As Integer = 1 To numbers.GetUpperBound(0)
                                     If numbers(ctr) = False Then primes.Add(ctr)
                                  Next

                                  ' Create the output string.
                                  For ctr As Integer = 0 To primes.Count - 1
                                     token.ThrowIfCancellationRequested()
                                     output += primes(ctr).ToString("N0")
                                     If ctr < primes.Count - 1 Then output += ",  "
                                     If (ctr + 1) Mod 8 = 0 Then output += vbCrLf
                                  Next
                                  'Display the result.
                                  Console.WriteLine("Prime numbers from 1 to {0}:{1}",
                                                    upperBound, vbCrLf)
                                  Console.WriteLine(output)
                               End Sub, token)
      Try
         t2.Wait()
      Catch ae As AggregateException
         For Each e In ae.InnerExceptions
            If e.GetType Is GetType(TaskCanceledException) Then
               Console.WriteLine("The operation was cancelled.")
            Else
               Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message)
            End If
         Next
      Finally
         ts.Dispose()
      End Try
   End Sub
   
   Private Sub TimedOutEvent(source As Object, e As Timers.ElapsedEventArgs)
      ts.Cancel()
   End Sub
End Module
' If cancellation is not requested, the example displays output like the following:
'       Prime numbers from 1 to 400:
'
'       1,  2,  3,  5,  7,  11,  13,  17,
'       19,  23,  29,  31,  37,  41,  43,  47,
'       53,  59,  61,  67,  71,  73,  79,  83,
'       89,  97,  101,  103,  107,  109,  113,  127,
'       131,  137,  139,  149,  151,  157,  163,  167,
'       173,  179,  181,  191,  193,  197,  199,  211,
'       223,  227,  229,  233,  239,  241,  251,  257,
'       263,  269,  271,  277,  281,  283,  293,  307,
'       311,  313,  317,  331,  337,  347,  349,  353,
'       359,  367,  373,  379,  383,  389,  397,  401
' If cancellation is requested, the example displays output like the following:
'       The operation was cancelled.

일반적으로 값 10만을 제공 하면 제한 시간 간격이 만료 되 고 Timer.Elapsed 이벤트와 설정 된 취소 요청이 발생 합니다.Typically, supplying a value of about 100,000 causes the timeout interval to expire and the Timer.Elapsed event to fire, and the cancellation request to be set.

설명

반환 된 Task는 현재 작업이 완료 될 때까지 실행 되도록 예약 되지 않습니다. 완료 될 때까지 실행 되거나, 처리 되지 않은 예외로 인해 오류가 발생 했거나, 취소 되어 초기에 종료 될 때까지 실행이 예약 되지 않습니다.The returned Task will not be scheduled for execution until the current task has completed, whether it completes due to running to completion successfully, faulting due to an unhandled exception, or exiting out early due to being canceled.

추가 정보

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

상태 정보가 전달되며 대상 Task<TResult>이 완료되면 실행되는 연속 작업을 만듭니다.Creates a continuation that is passed state information and that executes when the target Task<TResult> completes.

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

매개 변수

continuationAction
Action<Task<TResult>,Object>

Task<TResult>이 완료될 때 실행할 동작입니다.An action to run when the Task<TResult> completes. 실행되는 경우 대리자에게 완료된 작업과 호출자 제공 상태 개체가 인수로 전달됩니다.When run, the delegate is passed the completed task and the caller-supplied state object as arguments.

state
Object

연속 동작에서 사용할 데이터를 나타내는 개체입니다.An object representing data to be used by the continuation action.

반환

새 연속 Task입니다.A new continuation Task.

예외

continuationAction 인수가 null인 경우The continuationAction argument is null.

예제

다음 예에서는 2에서 20 사이의 정수로 전달 된 작업을 만들고 해당 숫자의 처음 10 개의 지수가 포함 된 배열 (n1 에서 n10까지)을 반환 합니다.The following example creates a task that is passed an integer between 2 and 20 and returns an array that contains the first ten exponents (from n1 to n10) of that number. 연속 작업을 담당 합니다는 지 수를 표시 합니다.A continuation task is then responsible for displaying the exponents. 선행 작업 및 원래 선행 작업에서 생성 된 지 수를 모두 전달 됩니다.It is passed both the antecedent and the original number whose exponents the antecedent generates.

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

public class Example
{
   public static void Main()
   {
      var cts = new CancellationTokenSource();
      var token = cts.Token;

      // Get an integer to generate a list of its exponents.
      var rnd = new Random();
      var number = rnd.Next(2, 21);
      
      var t = Task.Factory.StartNew( (value) => { int n = (int) value;
                                                  long[] values = new long[10];
                                                  for (int ctr = 1; ctr <= 10; ctr++)
                                                     values[ctr - 1] = (long) Math.Pow(n, ctr);
                                                     
                                                  return values;
                                                }, number);
      var continuation = t.ContinueWith( (antecedent, value) => { Console.WriteLine("Exponents of {0}:", value);
                                                                  for (int ctr = 0; ctr <= 9; ctr++)
                                                                     Console.WriteLine("   {0} {1} {2} = {3:N0}",
                                                                                       value, "\u02C6", ctr + 1,
                                                                                       antecedent.Result[ctr]);
                                                                  Console.WriteLine();
                                                                }, number);
      continuation.Wait();
      cts.Dispose();
   }
}
// The example displays output like the following:
//       Exponents of 2:
//          2 ^ 1 = 2
//          2 ^ 2 = 4
//          2 ^ 3 = 8
//          2 ^ 4 = 16
//          2 ^ 5 = 32
//          2 ^ 6 = 64
//          2 ^ 7 = 128
//          2 ^ 8 = 256
//          2 ^ 9 = 512
//          2 ^ 10 = 1,024
Imports System.Threading
Imports System.Threading.Tasks

Module Example
   Public Sub Main()
      Dim cts As New CancellationTokenSource()
      Dim token As CancellationToken = cts.Token

      ' Get an integer to generate a list of its exponents.
      Dim rnd As New Random()
      Dim number As Integer = rnd.Next(2, 21)

      Dim t = Task.Factory.StartNew( Function(value)
                                        Dim n As Integer = CInt(value)
                                        Dim values(9) As Long
                                        For ctr As Integer = 1 To 10
                                           values(ctr - 1) = CLng(Math.Pow(n, ctr))
                                        Next
                                        return values
                                     End Function, number)
      Dim continuation = t.ContinueWith( Sub(antecedent, value)
                                            Console.WriteLine("Exponents of {0}:", value)
                                            For ctr As Integer = 0 To 9
                                               Console.WriteLine("   {0} {1} {2} = {3:N0}",
                                                                 value, ChrW(&h02C6), ctr + 1,
                                                                 antecedent.Result(ctr))
                                            Next
                                            Console.WriteLine()
                                         End Sub, number)
      continuation.Wait()

      cts.Dispose()
   End Sub
End Module
' The example displays output like the following:
'       Exponents of 2:
'          2 ^ 1 = 2
'          2 ^ 2 = 4
'          2 ^ 3 = 8
'          2 ^ 4 = 16
'          2 ^ 5 = 32
'          2 ^ 6 = 64
'          2 ^ 7 = 128
'          2 ^ 8 = 256
'          2 ^ 9 = 512
'          2 ^ 10 = 1,024

설명

반환 된 Task는 현재 작업이 완료 될 때까지 실행 되도록 예약 되지 않습니다. 완료 될 때까지 실행 되거나, 처리 되지 않은 예외로 인해 오류가 발생 했거나, 취소 되어 초기에 종료 될 때까지 실행이 예약 되지 않습니다.The returned Task will not be scheduled for execution until the current task has completed, whether it completes due to running to completion successfully, faulting due to an unhandled exception, or exiting out early due to being canceled.

추가 정보

ContinueWith(Action<Task<TResult>>)

대상 작업이 완료될 때 비동기적으로 실행되는 연속 작업을 만듭니다.Creates a continuation that executes asynchronously when the target task completes.

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

매개 변수

continuationAction
Action<Task<TResult>>

Task<TResult> 선행 작업이 완료될 때 실행할 동작입니다.An action to run when the antecedent Task<TResult> completes. 실행될 때 이 대리자에는 완료된 작업이 인수로 전달됩니다.When run, the delegate will be passed the completed task as an argument.

반환

새 연속 작업입니다.A new continuation task.

예외

Task<TResult>가 삭제된 경우The Task<TResult> has been disposed.

continuationAction 인수가 null인 경우The continuationAction argument is null.

예제

다음 예제에서는 에라토스테네스의 체를 사용 하 여 사용자가 입력 한 값 1 사이의 소수를 계산 하는 선행 태스크를 만듭니다.The following example creates an antecedent task that uses the Sieve of Eratosthenes to calculate the prime numbers between 1 and a value entered by the user. 소수에 대 한 정보를 저장 하는 배열을 사용 됩니다.An array is used to hold information about the prime numbers. 배열 인덱스는 숫자를 나타내고, 요소의 값은 해당 숫자가 복합 형식 인지 (값 true) 또는 소수 (값은 false)를 나타냅니다.The array index represents the number, and the element's value indicates whether that number is composite (its value is true) or prime (its value is false). 그러면이 태스크는 정수 배열에서 소수를 추출 하 고 표시 하는 일을 담당 하는 연속 작업에 전달 됩니다.This task is then passed to a continuation task, which is responsible for extracting the prime numbers from the integer array and displaying them.

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

public class Example
{
   public static void Main(string[] args)
   {
      int upperBound = args.Length >= 1 ? Int32.Parse(args[0]) : 200;

      var t1 = Task.Run(() => { // True = composite.
                                // False = prime.
                                bool[] values = new bool[upperBound + 1];
                                for (int ctr = 2; ctr <= (int) Math.Sqrt(upperBound); ctr++) {
                                   if (values[ctr] == false) {
                                      for (int product = ctr * ctr; product <= upperBound;
                                                                    product = product + ctr)
                                         values[product] = true;
                                   }
                                }
                                return values; });
      var t2 = t1.ContinueWith( (antecedent) => { // Create a list of prime numbers.
                                                  var  primes = new List<int>();
                                                  bool[] numbers = antecedent.Result;
                                                  string output = String.Empty;

                                                  for (int ctr = 1; ctr <= numbers.GetUpperBound(0); ctr++)
                                                     if (numbers[ctr] == false)
                                                        primes.Add(ctr);

                                                  // Create the output string.
                                                  for (int ctr = 0; ctr < primes.Count; ctr++) {
                                                     output += primes[ctr].ToString("N0");
                                                     if (ctr < primes.Count - 1)
                                                        output += ",  ";
                                                     if ((ctr + 1) % 8 == 0)
                                                        output += Environment.NewLine;
                                                  }
                                                  //Display the result.
                                                  Console.WriteLine("Prime numbers from 1 to {0}:\n",
                                                                    upperBound);
                                                  Console.WriteLine(output);
                                                });
      try {
         t2.Wait();
      }
      catch (AggregateException ae) {
         foreach (var e in ae.InnerExceptions)
            Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message);
      }
   }
}
// The example displays output like the following:
//       Prime numbers from 1 to 400:
//
//       1,  2,  3,  5,  7,  11,  13,  17,
//       19,  23,  29,  31,  37,  41,  43,  47,
//       53,  59,  61,  67,  71,  73,  79,  83,
//       89,  97,  101,  103,  107,  109,  113,  127,
//       131,  137,  139,  149,  151,  157,  163,  167,
//       173,  179,  181,  191,  193,  197,  199,  211,
//       223,  227,  229,  233,  239,  241,  251,  257,
//       263,  269,  271,  277,  281,  283,  293,  307,
//       311,  313,  317,  331,  337,  347,  349,  353,
//       359,  367,  373,  379,  383,  389,  397,  401
Imports System.Collections.Generic
Imports System.Threading
Imports System.Threading.Tasks

Module Example
   Public Sub Main(args() As String)
      Dim upperBound As Integer = If(args.Length >= 1, CInt(args(0)), 200)

      Dim t1 = Task.Run(Function()
                          ' True = composite.
                          ' False = prime.
                          Dim values(upperBound) As Boolean
                          For ctr = 2 To CInt(Math.Sqrt(upperBound))
                             If values(ctr) = False Then
                                For product = ctr * ctr To upperBound Step ctr
                                   values(product) = True
                                Next
                             End If
                          Next
                          Return values
                       End Function)

      Dim t2 = t1.ContinueWith(Sub(antecedent)
                                  ' Create a list of prime numbers.
                                  Dim primes As New List(Of Integer)()
                                  Dim numbers As Boolean() = antecedent.Result
                                  Dim output As String = String.Empty
                                  
                                  For ctr As Integer = 1 To numbers.GetUpperBound(0)
                                     If numbers(ctr) = False Then primes.Add(ctr)
                                  Next

                                  ' Create the output string.
                                  For ctr As Integer = 0 To primes.Count - 1
                                     output += primes(ctr).ToString("N0")
                                     If ctr < primes.Count - 1 Then output += ",  "
                                     If (ctr + 1) Mod 8 = 0 Then output += vbCrLf
                                  Next
                                  'Display the result.
                                  Console.WriteLine("Prime numbers from 1 to {0}:{1}",
                                                    upperBound, vbCrLf)
                                  Console.WriteLine(output)
                               End Sub)
      Try
         t2.Wait()
      Catch ae As AggregateException
         For Each e In ae.InnerExceptions
            Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message)
         Next
      End Try
   End Sub
End Module
' The example displays output like the following:
'       Prime numbers from 1 to 400:
'
'       1,  2,  3,  5,  7,  11,  13,  17,
'       19,  23,  29,  31,  37,  41,  43,  47,
'       53,  59,  61,  67,  71,  73,  79,  83,
'       89,  97,  101,  103,  107,  109,  113,  127,
'       131,  137,  139,  149,  151,  157,  163,  167,
'       173,  179,  181,  191,  193,  197,  199,  211,
'       223,  227,  229,  233,  239,  241,  251,  257,
'       263,  269,  271,  277,  281,  283,  293,  307,
'       311,  313,  317,  331,  337,  347,  349,  353,
'       359,  367,  373,  379,  383,  389,  397,  401
' If cancellation is requested, the example displays output like the following:
'       The operation was cancelled.

설명

반환 된 Task는 현재 작업이 완료 될 때까지 실행 하도록 예약 되지 않으며, 성공적으로 완료 될 때까지 실행 되거나, 처리 되지 않은 예외로 인해 오류가 발생 하거나, 취소 되어 초기에 종료 됩니다.The returned Task will not be scheduled for execution until the current task has completed, whether it completes due to running to completion successfully, faulting due to an unhandled exception, or exiting early due to being canceled.

추가 정보

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

대상 Task<TResult>가 완료될 때 비동기적으로 실행되는 연속 작업을 만듭니다.Creates a continuation that executes asynchronously when the target Task<TResult> completes.

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

매개 변수

continuationAction
Action<Task<TResult>>

Task<TResult>이 완료될 때 실행할 동작입니다.An action to run when the Task<TResult> completes. 실행될 때 이 대리자에는 완료된 작업이 인수로 전달됩니다.When run, the delegate will be passed the completed task as an argument.

scheduler
TaskScheduler

연속 작업과 연결하고 연속 작업의 실행에 사용할 TaskScheduler입니다.The TaskScheduler to associate with the continuation task and to use for its execution.

반환

새 연속 Task입니다.A new continuation Task.

예외

Task<TResult>가 삭제된 경우The Task<TResult> has been disposed.

continuationAction 인수가 null인 경우The continuationAction argument is null.

또는-or- scheduler 인수가 null인 경우The scheduler argument is null.

설명

반환 된 Task는 현재 작업이 완료 될 때까지 실행 되도록 예약 되지 않습니다. 완료 될 때까지 실행 되거나, 처리 되지 않은 예외로 인해 오류가 발생 했거나, 취소 되어 초기에 종료 될 때까지 실행이 예약 되지 않습니다.The returned Task will not be scheduled for execution until the current task has completed, whether it completes due to running to completion successfully, faulting due to an unhandled exception, or exiting out early due to being canceled.

추가 정보

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

대상 Task<TResult>이 완료될 때 실행되는 연속 작업을 만듭니다.Creates a continuation that executes when the target Task<TResult> completes.

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

형식 매개 변수

TNewResult

연속 작업에서 생성되는 결과의 형식입니다.The type of the result produced by the continuation.

매개 변수

continuationFunction
Func<Task<TResult>,Object,TNewResult>

Task<TResult>이 완료될 때 실행할 함수입니다.A function to run when the Task<TResult> completes. 실행되는 경우 대리자에게 완료된 작업과 호출자 제공 상태 개체가 인수로 전달됩니다.When run, the delegate will be passed the completed task and the caller-supplied state object as arguments.

state
Object

연속 함수에서 사용할 데이터를 나타내는 개체입니다.An object representing data to be used by the continuation function.

cancellationToken
CancellationToken

새 작업에 할당할 CancellationToken입니다.The CancellationToken that will be assigned to the new task.

continuationOptions
TaskContinuationOptions

연속 작업이 예약되는 시기와 연속 작업이 동작하는 방식에 대한 옵션입니다.Options for when the continuation is scheduled and how it behaves. 여기에는 OnlyOnCanceled와 같은 조건과 ExecuteSynchronously 등의 실행 옵션이 포함됩니다.This includes criteria, such as OnlyOnCanceled, as well as execution options, such as ExecuteSynchronously.

scheduler
TaskScheduler

연속 작업과 연결하고 연속 작업의 실행에 사용할 TaskScheduler입니다.The TaskScheduler to associate with the continuation task and to use for its execution.

반환

Task<TNewResult>

새 연속 Task<TResult>입니다.A new continuation Task<TResult>.

예외

scheduler 인수가 null인 경우The scheduler argument is null.

continuationOptions 인수는 TaskContinuationOptions에 대해 잘못된 값을 지정합니다.The continuationOptions argument specifies an invalid value for TaskContinuationOptions.

제공된 CancellationToken가 이미 삭제된 경우The provided CancellationToken has already been disposed.

설명

반환 된 Task<TResult>는 현재 작업이 완료 될 때까지 실행 되도록 예약 되지 않습니다. 완료 될 때까지 실행 되거나, 처리 되지 않은 예외로 인해 오류가 발생 했거나, 취소 되어 초기에 종료 될 때까지 실행이 예약 되지 않습니다.The returned Task<TResult> will not be scheduled for execution until the current task has completed, whether it completes due to running to completion successfully, faulting due to an unhandled exception, or exiting out early due to being canceled.

continuationFunction를 실행 하면 Task<TResult>을 반환 해야 합니다.The continuationFunction, when executed, should return a Task<TResult>. 이 작업의 완료 상태는 Task<TResult>.ContinueWith 호출에서 반환 된 작업으로 전송 됩니다.This task's completion state will be transferred to the task returned from the Task<TResult>.ContinueWith call.

추가 정보

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

continuationOptions에 지정된 조건에 따라 실행되는 연속 작업을 만듭니다.Creates a continuation that executes according the condition specified in continuationOptions.

public:
generic <typename TNewResult>
 System::Threading::Tasks::Task<TNewResult> ^ ContinueWith(Func<System::Threading::Tasks::Task<TResult> ^, TNewResult> ^ continuationFunction, System::Threading::CancellationToken cancellationToken, System::Threading::Tasks::TaskContinuationOptions continuationOptions, System::Threading::Tasks::TaskScheduler ^ scheduler);
public System.Threading.Tasks.Task<TNewResult> ContinueWith<TNewResult> (Func<System.Threading.Tasks.Task<TResult>,TNewResult> continuationFunction, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskContinuationOptions continuationOptions, System.Threading.Tasks.TaskScheduler scheduler);
override this.ContinueWith : Func<System.Threading.Tasks.Task<'Result>, 'NewResult> * System.Threading.CancellationToken * System.Threading.Tasks.TaskContinuationOptions * System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.Task<'NewResult>

형식 매개 변수

TNewResult

연속 작업에서 생성되는 결과의 형식입니다.The type of the result produced by the continuation.

매개 변수

continuationFunction
Func<Task<TResult>,TNewResult>

continuationOptions에 지정된 조건에 따라 실행할 함수입니다.A function to run according the condition specified in continuationOptions.

실행될 때 이 대리자에는 완료된 작업이 인수로 전달됩니다.When run, the delegate will be passed as an argument this completed task.

cancellationToken
CancellationToken

새 작업에 할당할 CancellationToken입니다.The CancellationToken that will be assigned to the new task.

continuationOptions
TaskContinuationOptions

연속 작업이 예약되는 시기와 연속 작업이 동작하는 방식에 대한 옵션입니다.Options for when the continuation is scheduled and how it behaves. 여기에는 OnlyOnCanceled와 같은 조건과 ExecuteSynchronously 등의 실행 옵션이 포함됩니다.This includes criteria, such as OnlyOnCanceled, as well as execution options, such as ExecuteSynchronously.

scheduler
TaskScheduler

연속 작업과 연결하고 연속 작업의 실행에 사용할 TaskScheduler입니다.The TaskScheduler to associate with the continuation task and to use for its execution.

반환

Task<TNewResult>

새 연속 Task<TResult>입니다.A new continuation Task<TResult>.

예외

Task<TResult>가 삭제된 경우The Task<TResult> has been disposed.

또는-or- cancellationToken을 만든 CancellationTokenSource가 이미 삭제되었습니다.The CancellationTokenSource that created cancellationToken has already been disposed.

continuationFunction 인수가 null인 경우The continuationFunction argument is null.

또는-or- scheduler 인수가 null인 경우The scheduler argument is null.

continuationOptions 인수는 TaskContinuationOptions에 대해 잘못된 값을 지정합니다.The continuationOptions argument specifies an invalid value for TaskContinuationOptions.

설명

반환 된 Task<TResult>는 현재 작업이 완료 될 때까지 실행 되도록 예약 되지 않습니다. 완료 될 때까지 실행 되거나, 처리 되지 않은 예외로 인해 오류가 발생 했거나, 취소 되어 초기에 종료 될 때까지 실행이 예약 되지 않습니다.The returned Task<TResult> will not be scheduled for execution until the current task has completed, whether it completes due to running to completion successfully, faulting due to an unhandled exception, or exiting out early due to being canceled.

continuationFunction를 실행 하면 Task<TResult>을 반환 해야 합니다.The continuationFunction, when executed, should return a Task<TResult>.

추가 정보

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

대상 Task<TResult>이 완료될 때 실행되는 연속 작업을 만듭니다.Creates a continuation that executes when the target Task<TResult> completes.

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

형식 매개 변수

TNewResult

연속 작업에서 생성되는 결과의 형식입니다.The type of the result produced by the continuation.

매개 변수

continuationFunction
Func<Task<TResult>,Object,TNewResult>

Task<TResult>이 완료될 때 실행할 함수입니다.A function to run when the Task<TResult> completes. 실행되는 경우 대리자에게 완료된 작업과 호출자 제공 상태 개체가 인수로 전달됩니다.When run, the delegate will be passed the completed task and the caller-supplied state object as arguments.

state
Object

연속 함수에서 사용할 데이터를 나타내는 개체입니다.An object representing data to be used by the continuation function.

scheduler
TaskScheduler

연속 작업과 연결하고 연속 작업의 실행에 사용할 TaskScheduler입니다.The TaskScheduler to associate with the continuation task and to use for its execution.

반환

Task<TNewResult>

새 연속 Task<TResult>입니다.A new continuation Task<TResult>.

예외

scheduler 인수가 null인 경우The scheduler argument is null.

설명

반환 된 Task<TResult>는 현재 작업이 완료 될 때까지 실행 되도록 예약 되지 않습니다. 완료 될 때까지 실행 되거나, 처리 되지 않은 예외로 인해 오류가 발생 했거나, 취소 되어 초기에 종료 될 때까지 실행이 예약 되지 않습니다.The returned Task<TResult> will not be scheduled for execution until the current task has completed, whether it completes due to running to completion successfully, faulting due to an unhandled exception, or exiting out early due to being canceled.

추가 정보

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

대상 Task<TResult>이 완료될 때 실행되는 연속 작업을 만듭니다.Creates a continuation that executes when the target Task<TResult> completes.

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

형식 매개 변수

TNewResult

연속 작업에서 생성되는 결과의 형식입니다.The type of the result produced by the continuation.

매개 변수

continuationFunction
Func<Task<TResult>,Object,TNewResult>

Task<TResult>이 완료될 때 실행할 함수입니다.A function to run when the Task<TResult> completes. 실행되는 경우 대리자에게 완료된 작업과 호출자 제공 상태 개체가 인수로 전달됩니다.When run, the delegate will be passed the completed task and the caller-supplied state object as arguments.

state
Object

연속 함수에서 사용할 데이터를 나타내는 개체입니다.An object representing data to be used by the continuation function.

continuationOptions
TaskContinuationOptions

연속 작업이 예약되는 시기와 연속 작업이 동작하는 방식에 대한 옵션입니다.Options for when the continuation is scheduled and how it behaves. 여기에는 OnlyOnCanceled와 같은 조건과 ExecuteSynchronously 등의 실행 옵션이 포함됩니다.This includes criteria, such as OnlyOnCanceled, as well as execution options, such as ExecuteSynchronously.

반환

Task<TNewResult>

새 연속 Task<TResult>입니다.A new continuation Task<TResult>.

예외

continuationFunction 인수가 null인 경우The continuationFunction argument is null.

continuationOptions 인수는 TaskContinuationOptions에 대해 잘못된 값을 지정합니다.The continuationOptions argument specifies an invalid value for TaskContinuationOptions.

설명

반환 된 Task<TResult>는 현재 작업이 완료 될 때까지 실행 되도록 예약 되지 않습니다. 완료 될 때까지 실행 되거나, 처리 되지 않은 예외로 인해 오류가 발생 했거나, 취소 되어 초기에 종료 될 때까지 실행이 예약 되지 않습니다.The returned Task<TResult> will not be scheduled for execution until the current task has completed, whether it completes due to running to completion successfully, faulting due to an unhandled exception, or exiting out early due to being canceled.

continuationFunction를 실행 하면 Task<TResult>을 반환 해야 합니다.The continuationFunction, when executed, should return a Task<TResult>. 이 작업의 완료 상태 ContinueWith 호출에서 반환 된 작업에 전송 됩니다.This task's completion state will be transferred to the task returned from the ContinueWith call.

추가 정보

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

대상 Task<TResult>이 완료될 때 실행되는 연속 작업을 만듭니다.Creates a continuation that executes when the target Task<TResult> completes.

public:
generic <typename TNewResult>
 System::Threading::Tasks::Task<TNewResult> ^ ContinueWith(Func<System::Threading::Tasks::Task<TResult> ^, System::Object ^, TNewResult> ^ continuationFunction, System::Object ^ state, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<TNewResult> ContinueWith<TNewResult> (Func<System.Threading.Tasks.Task<TResult>,object,TNewResult> continuationFunction, object state, System.Threading.CancellationToken cancellationToken);
override this.ContinueWith : Func<System.Threading.Tasks.Task<'Result>, obj, 'NewResult> * obj * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'NewResult>

형식 매개 변수

TNewResult

연속 작업에서 생성되는 결과의 형식입니다.The type of the result produced by the continuation.

매개 변수

continuationFunction
Func<Task<TResult>,Object,TNewResult>

Task<TResult>이 완료될 때 실행할 함수입니다.A function to run when the Task<TResult> completes. 실행되는 경우 대리자에게 완료된 작업과 호출자 제공 상태 개체가 인수로 전달됩니다.When run, the delegate will be passed the completed task and the caller-supplied state object as arguments.

state
Object

연속 함수에서 사용할 데이터를 나타내는 개체입니다.An object representing data to be used by the continuation function.

cancellationToken
CancellationToken

새 작업에 할당할 CancellationToken입니다.The CancellationToken that will be assigned to the new task.

반환

Task<TNewResult>

새 연속 Task<TResult>입니다.A new continuation Task<TResult>.

예외

continuationFunction 인수가 null인 경우The continuationFunction argument is null.

제공된 CancellationToken가 이미 삭제된 경우The provided CancellationToken has already been disposed.

설명

반환 된 Task<TResult>는 현재 작업이 완료 될 때까지 실행 되도록 예약 되지 않습니다. 완료 될 때까지 실행 되거나, 처리 되지 않은 예외로 인해 오류가 발생 했거나, 취소 되어 초기에 종료 될 때까지 실행이 예약 되지 않습니다.The returned Task<TResult> will not be scheduled for execution until the current task has completed, whether it completes due to running to completion successfully, faulting due to an unhandled exception, or exiting out early due to being canceled.

추가 정보

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

continuationOptions에 지정된 조건에 따라 실행되는 연속 작업을 만듭니다.Creates a continuation that executes according the condition specified in continuationOptions.

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

형식 매개 변수

TNewResult

연속 작업에서 생성되는 결과의 형식입니다.The type of the result produced by the continuation.

매개 변수

continuationFunction
Func<Task<TResult>,TNewResult>

continuationOptions에 지정된 조건에 따라 실행할 함수입니다.A function to run according the condition specified in continuationOptions.

실행될 때 이 대리자에는 완료된 작업이 인수로 전달됩니다.When run, the delegate will be passed the completed task as an argument.

continuationOptions
TaskContinuationOptions

연속 작업이 예약되는 시기와 연속 작업이 동작하는 방식에 대한 옵션입니다.Options for when the continuation is scheduled and how it behaves. 여기에는 OnlyOnCanceled와 같은 조건과 ExecuteSynchronously 등의 실행 옵션이 포함됩니다.This includes criteria, such as OnlyOnCanceled, as well as execution options, such as ExecuteSynchronously.

반환

Task<TNewResult>

새 연속 Task<TResult>입니다.A new continuation Task<TResult>.

예외

Task<TResult>가 삭제된 경우The Task<TResult> has been disposed.

continuationFunction 인수가 null인 경우The continuationFunction argument is null.

continuationOptions 인수는 TaskContinuationOptions에 대해 잘못된 값을 지정합니다.The continuationOptions argument specifies an invalid value for TaskContinuationOptions.

설명

반환 된 Task<TResult>는 현재 작업이 완료 될 때까지 실행 되도록 예약 되지 않습니다. 완료 될 때까지 실행 되거나, 처리 되지 않은 예외로 인해 오류가 발생 했거나, 취소 되어 초기에 종료 될 때까지 실행이 예약 되지 않습니다.The returned Task<TResult> will not be scheduled for execution until the current task has completed, whether it completes due to running to completion successfully, faulting due to an unhandled exception, or exiting out early due to being canceled.

continuationFunction를 실행 하면 Task<TResult>을 반환 해야 합니다.The continuationFunction, when executed, should return a Task<TResult>.

추가 정보

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

대상 Task<TResult>가 완료될 때 비동기적으로 실행되는 연속 작업을 만듭니다.Creates a continuation that executes asynchronously when the target Task<TResult> completes.

public:
generic <typename TNewResult>
 System::Threading::Tasks::Task<TNewResult> ^ ContinueWith(Func<System::Threading::Tasks::Task<TResult> ^, TNewResult> ^ continuationFunction, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task<TNewResult> ContinueWith<TNewResult> (Func<System.Threading.Tasks.Task<TResult>,TNewResult> continuationFunction, System.Threading.CancellationToken cancellationToken);
override this.ContinueWith : Func<System.Threading.Tasks.Task<'Result>, 'NewResult> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'NewResult>

형식 매개 변수

TNewResult

연속 작업에서 생성되는 결과의 형식입니다.The type of the result produced by the continuation.

매개 변수

continuationFunction
Func<Task<TResult>,TNewResult>

Task<TResult>이 완료될 때 실행할 함수입니다.A function to run when the Task<TResult> completes. 실행될 때 이 대리자에는 완료된 작업이 인수로 전달됩니다.When run, the delegate will be passed the completed task as an argument.

cancellationToken
CancellationToken

새 작업에 할당할 CancellationToken입니다.The CancellationToken that will be assigned to the new task.

반환

Task<TNewResult>

새 연속 Task<TResult>입니다.A new continuation Task<TResult>.

예외

Task<TResult>가 삭제된 경우The Task<TResult> has been disposed.

또는-or- cancellationToken을 만든 CancellationTokenSource가 이미 삭제되었습니다.The CancellationTokenSource that created cancellationToken has already been disposed.

continuationFunction 인수가 null인 경우The continuationFunction argument is null.

설명

반환 된 Task<TResult>는 현재 작업이 완료 될 때까지 실행 되도록 예약 되지 않습니다. 완료 될 때까지 실행 되거나, 처리 되지 않은 예외로 인해 오류가 발생 했거나, 취소 되어 초기에 종료 될 때까지 실행이 예약 되지 않습니다.The returned Task<TResult> will not be scheduled for execution until the current task has completed, whether it completes due to running to completion successfully, faulting due to an unhandled exception, or exiting out early due to being canceled.

추가 정보

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

대상 Task<TResult>이 완료될 때 실행되는 연속 작업을 만듭니다.Creates a continuation that executes when the target Task<TResult> completes.

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

형식 매개 변수

TNewResult

연속 작업에서 생성되는 결과의 형식입니다.The type of the result produced by the continuation.

매개 변수

continuationFunction
Func<Task<TResult>,Object,TNewResult>

Task<TResult>이 완료될 때 실행할 함수입니다.A function to run when the Task<TResult> completes. 실행되는 경우 대리자에게 완료된 작업과 호출자 제공 상태 개체가 인수로 전달됩니다.When run, the delegate will be passed the completed task and the caller-supplied state object as arguments.

state
Object

연속 함수에서 사용할 데이터를 나타내는 개체입니다.An object representing data to be used by the continuation function.

반환

Task<TNewResult>

새 연속 Task<TResult>입니다.A new continuation Task<TResult>.

예외

continuationFunction 인수가 null인 경우The continuationFunction argument is null.

예제

다음 예제에서는 연속 작업의 체인을 만듭니다.The following example creates a chain of continuation tasks. 각 작업은 ContinueWith(Action<Task,Object>, Object) 메서드의 상태 인수에 대해 현재 시간 DateTime 개체를 제공 합니다.Each task provides the current time, a DateTime object, for the state argument of the ContinueWith(Action<Task,Object>, Object) method. DateTime 값은 continue 작업이 만들어진 시간을 나타냅니다.Each DateTime value represents the time at which the continue task is created. 각 작업은 작업 완료 시간을 나타내는 두 번째 DateTime 값을 결과로 생성 합니다.Each task produces as its result a second DateTime value that represents the time at which the task finishes. 모든 작업을 마친 후 예제에서는 날짜 및 시간 각 연속 작업을 시작 및 완료를 표시 합니다.After all tasks finish, the example displays the date and times at which each continuation task starts and finishes.

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

// Demonstrates how to associate state with task continuations.
class ContinuationState
{
   // Simluates a lengthy operation and returns the time at which
   // the operation completed.
   public static DateTime DoWork()
   {
      // Simulate work by suspending the current thread 
      // for two seconds.
      Thread.Sleep(2000);

      // Return the current time.
      return DateTime.Now;
   }

   static void Main(string[] args)
   {
      // Start a root task that performs work.
      Task<DateTime> t = Task<DateTime>.Run(delegate { return DoWork(); });

      // Create a chain of continuation tasks, where each task is 
      // followed by another task that performs work.
      List<Task<DateTime>> continuations = new List<Task<DateTime>>();
      for (int i = 0; i < 5; i++)
      {
         // Provide the current time as the state of the continuation.
         t = t.ContinueWith(delegate { return DoWork(); }, DateTime.Now);
         continuations.Add(t);
      }

      // Wait for the last task in the chain to complete.
      t.Wait();

      // Print the creation time of each continuation (the state object)
      // and the completion time (the result of that task) to the console.
      foreach (var continuation in continuations)
      {
         DateTime start = (DateTime)continuation.AsyncState;
         DateTime end = continuation.Result;

         Console.WriteLine("Task was created at {0} and finished at {1}.",
            start.TimeOfDay, end.TimeOfDay);
      }
   }
}

/* Sample output:
Task was created at 10:56:21.1561762 and finished at 10:56:25.1672062.
Task was created at 10:56:21.1610677 and finished at 10:56:27.1707646.
Task was created at 10:56:21.1610677 and finished at 10:56:29.1743230.
Task was created at 10:56:21.1610677 and finished at 10:56:31.1779883.
Task was created at 10:56:21.1610677 and finished at 10:56:33.1837083.
*/
Imports System.Collections.Generic
Imports System.Threading
Imports System.Threading.Tasks

' Demonstrates how to associate state with task continuations.
Public Module ContinuationState
   ' Simluates a lengthy operation and returns the time at which
   ' the operation completed.
   Public Function DoWork() As Date
      ' Simulate work by suspending the current thread 
      ' for two seconds.
      Thread.Sleep(2000)

      ' Return the current time.
      Return Date.Now
   End Function

   Public Sub Main()
      ' Start a root task that performs work.
      Dim t As Task(Of Date) = Task(Of Date).Run(Function() DoWork())

      ' Create a chain of continuation tasks, where each task is
      ' followed by another task that performs work.
      Dim continuations As New List(Of Task(Of DateTime))()
      For i As Integer = 0 To 4
         ' Provide the current time as the state of the continuation.
         t = t.ContinueWith(Function(antecedent, state) DoWork(), DateTime.Now)
         continuations.Add(t)
      Next

      ' Wait for the last task in the chain to complete.
      t.Wait()

      ' Display the creation time of each continuation (the state object)
      ' and the completion time (the result of that task) to the console.
      For Each continuation In continuations
         Dim start As DateTime = CDate(continuation.AsyncState)
         Dim [end] As DateTime = continuation.Result

         Console.WriteLine("Task was created at {0} and finished at {1}.",
            start.TimeOfDay, [end].TimeOfDay)
      Next
   End Sub
End Module
' The example displays output like the following:
'       Task was created at 10:56:21.1561762 and finished at 10:56:25.1672062.
'       Task was created at 10:56:21.1610677 and finished at 10:56:27.1707646.
'       Task was created at 10:56:21.1610677 and finished at 10:56:29.1743230.
'       Task was created at 10:56:21.1610677 and finished at 10:56:31.1779883.
'       Task was created at 10:56:21.1610677 and finished at 10:56:33.1837083.

설명

반환 된 Task<TResult>는 현재 작업이 완료 될 때까지 실행 되도록 예약 되지 않습니다. 완료 될 때까지 실행 되거나, 처리 되지 않은 예외로 인해 오류가 발생 했거나, 취소 되어 초기에 종료 될 때까지 실행이 예약 되지 않습니다.The returned Task<TResult> will not be scheduled for execution until the current task has completed, whether it completes due to running to completion successfully, faulting due to an unhandled exception, or exiting out early due to being canceled.

추가 정보

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

대상 Task<TResult>가 완료될 때 비동기적으로 실행되는 연속 작업을 만듭니다.Creates a continuation that executes asynchronously when the target Task<TResult> completes.

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

형식 매개 변수

TNewResult

연속 작업에서 생성되는 결과의 형식입니다.The type of the result produced by the continuation.

매개 변수

continuationFunction
Func<Task<TResult>,TNewResult>

Task<TResult>이 완료될 때 실행할 함수입니다.A function to run when the Task<TResult> completes. 실행될 때 이 대리자에는 완료된 작업이 인수로 전달됩니다.When run, the delegate will be passed the completed task as an argument.

반환

Task<TNewResult>

새 연속 Task<TResult>입니다.A new continuation Task<TResult>.

예외

Task<TResult>가 삭제된 경우The Task<TResult> has been disposed.

continuationFunction 인수가 null인 경우The continuationFunction argument is null.

설명

반환 된 Task<TResult>는 현재 작업이 완료 될 때까지 실행 되도록 예약 되지 않습니다. 완료 될 때까지 실행 되거나, 처리 되지 않은 예외로 인해 오류가 발생 했거나, 취소 되어 초기에 종료 될 때까지 실행이 예약 되지 않습니다.The returned Task<TResult> will not be scheduled for execution until the current task has completed, whether it completes due to running to completion successfully, faulting due to an unhandled exception, or exiting out early due to being canceled.

추가 정보

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

대상 Task<TResult>가 완료될 때 비동기적으로 실행되는 연속 작업을 만듭니다.Creates a continuation that executes asynchronously when the target Task<TResult> completes.

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

형식 매개 변수

TNewResult

연속 작업에서 생성되는 결과의 형식입니다.The type of the result produced by the continuation.

매개 변수

continuationFunction
Func<Task<TResult>,TNewResult>

Task<TResult>이 완료될 때 실행할 함수입니다.A function to run when the Task<TResult> completes. 실행될 때 이 대리자에는 완료된 작업이 인수로 전달됩니다.When run, the delegate will be passed the completed task as an argument.

scheduler
TaskScheduler

연속 작업과 연결하고 연속 작업의 실행에 사용할 TaskScheduler입니다.The TaskScheduler to associate with the continuation task and to use for its execution.

반환

Task<TNewResult>

새 연속 Task<TResult>입니다.A new continuation Task<TResult>.

예외

Task<TResult>가 삭제된 경우The Task<TResult> has been disposed.

continuationFunction 인수가 null인 경우The continuationFunction argument is null.

또는-or- scheduler 인수가 null인 경우The scheduler argument is null.

설명

반환 된 Task<TResult>는 현재 작업이 완료 될 때까지 실행 되도록 예약 되지 않습니다. 완료 될 때까지 실행 되거나, 처리 되지 않은 예외로 인해 오류가 발생 했거나, 취소 되어 초기에 종료 될 때까지 실행이 예약 되지 않습니다.The returned Task<TResult> will not be scheduled for execution until the current task has completed, whether it completes due to running to completion successfully, faulting due to an unhandled exception, or exiting out early due to being canceled.

추가 정보

적용 대상