Task Task Task Task Constructors

정의

오버로드

Task(Action) Task(Action) Task(Action)

지정된 작업을 사용하여 새 Task를 초기화합니다.Initializes a new Task with the specified action.

Task(Action, CancellationToken) Task(Action, CancellationToken) Task(Action, CancellationToken)

지정된 작업을 사용하여 새 TaskCancellationToken을 초기화합니다.Initializes a new Task with the specified action and CancellationToken.

Task(Action, TaskCreationOptions) Task(Action, TaskCreationOptions) Task(Action, TaskCreationOptions)

지정된 작업 및 만들기 옵션을 사용하여 새 Task를 초기화합니다.Initializes a new Task with the specified action and creation options.

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

지정된 작업 및 상태를 사용하여 새 Task를 초기화합니다.Initializes a new Task with the specified action and state.

Task(Action, CancellationToken, TaskCreationOptions) Task(Action, CancellationToken, TaskCreationOptions) Task(Action, CancellationToken, TaskCreationOptions)

지정된 작업 및 만들기 옵션을 사용하여 새 Task를 초기화합니다.Initializes a new Task with the specified action and creation options.

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

지정된 작업, 상태 및 옵션을 사용하여 새 Task를 초기화합니다.Initializes a new Task with the specified action, state, and options.

Task(Action<Object>, Object, TaskCreationOptions) Task(Action<Object>, Object, TaskCreationOptions) Task(Action<Object>, Object, TaskCreationOptions) Task(Action<Object>, Object, TaskCreationOptions)

지정된 작업, 상태 및 옵션을 사용하여 새 Task를 초기화합니다.Initializes a new Task with the specified action, state, and options.

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

지정된 작업, 상태 및 옵션을 사용하여 새 Task를 초기화합니다.Initializes a new Task with the specified action, state, and options.

Task(Action) Task(Action) Task(Action)

지정된 작업을 사용하여 새 Task를 초기화합니다.Initializes a new Task with the specified action.

public:
 Task(Action ^ action);
public Task (Action action);
new System.Threading.Tasks.Task : Action -> System.Threading.Tasks.Task

매개 변수

action
Action Action Action Action

작업에서 실행할 코드를 나타내는 대리자입니다.The delegate that represents the code to execute in the task.

예외

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

예제

다음 예제에서는 Task(Action) 생성자에서 파일 이름을 검색 하는 작업을 만드는 디렉터리를 지정 합니다.The following example uses the Task(Action) constructor to create tasks that retrieve the filenames in specified directories. 모든 작업을 단일 파일 이름을 쓸 ConcurrentBag<T> 개체입니다.All tasks write the file names to a single ConcurrentBag<T> object. 다음 호출 하 여 합니다 WaitAll(Task[]) 모든 작업을 완료 하 고 다음에 기록 하는 파일 이름의 총 개수를 표시 하도록 메서드를 ConcurrentBag<T> 개체입니다.The example then calls the WaitAll(Task[]) method to ensure that all tasks have completed, and then displays a count of the total number of file names written to the ConcurrentBag<T> object.

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

public class Example
{
   public static async Task Main()
   {
      var list = new ConcurrentBag<string>();
      string[] dirNames = { ".", ".." };
      List<Task> tasks = new List<Task>();
      foreach (var dirName in dirNames) {
         Task t = new Task( () => { foreach(var path in Directory.GetFiles(dirName))
                                    list.Add(path); }  );
         tasks.Add(t);
         t.Start();
      }
      await Task.WhenAll(tasks.ToArray());
      foreach (Task t in tasks)
         Console.WriteLine("Task {0} Status: {1}", t.Id, t.Status);
         
      Console.WriteLine("Number of files read: {0}", list.Count);
   }
}
// The example displays output like the following:
//       Task 1 Status: RanToCompletion
//       Task 2 Status: RanToCompletion
//       Number of files read: 23
Imports System.Collections.Concurrent
Imports System.Collections.Generic
Imports System.IO
Imports System.Threading.Tasks

Module Example
   Public Sub Main()
      Dim list As New ConcurrentBag(Of String)()
      Dim dirNames() As String = { ".", ".." }
      Dim tasks As New List(Of Task)()
      For Each dirName In dirNames 
         Dim t As New Task( Sub()
                               For Each path In Directory.GetFiles(dirName)
                                  list.Add(path)
                               Next
                            End Sub  )
         tasks.Add(t)
         t.Start()
      Next
      Task.WaitAll(tasks.ToArray())
      For Each t In tasks
         Console.WriteLine("Task {0} Status: {1}", t.Id, t.Status)
      Next   
      Console.WriteLine("Number of files read: {0}", list.Count)
   End Sub
End Module
' The example displays output like the following:
'       Task 1 Status: RanToCompletion
'       Task 2 Status: RanToCompletion
'       Number of files read: 23

다음 예제는 사용 한다는 점을 제외 하면 동일 합니다 Run(Action) 메서드를 인스턴스화할 때 단일 작업에서 작업을 실행 합니다.The following example is identical, except that it used the Run(Action) method to instantiate and run the task in a single operation. 메서드는 반환 된 Task 작업을 나타내는 개체입니다.The method returns the Task object that represents the task.

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

public class Example
{
   public static void Main()
   {
      var list = new ConcurrentBag<string>();
      string[] dirNames = { ".", ".." };
      List<Task> tasks = new List<Task>();
      foreach (var dirName in dirNames) {
         Task t = Task.Run( () => { foreach(var path in Directory.GetFiles(dirName)) 
                                       list.Add(path); }  );
         tasks.Add(t);
      }
      Task.WaitAll(tasks.ToArray());
      foreach (Task t in tasks)
         Console.WriteLine("Task {0} Status: {1}", t.Id, t.Status);
         
      Console.WriteLine("Number of files read: {0}", list.Count);
   }
}
// The example displays output like the following:
//       Task 1 Status: RanToCompletion
//       Task 2 Status: RanToCompletion
//       Number of files read: 23
Imports System.Collections.Concurrent
Imports System.Collections.Generic
Imports System.IO
Imports System.Threading.Tasks

Module Example
   Public Sub Main()
      Dim list As New ConcurrentBag(Of String)()
      Dim dirNames() As String = { ".", ".." }
      Dim tasks As New List(Of Task)()
      For Each dirName In dirNames 
         Dim t As Task = Task.Run( Sub()
                                      For Each path In Directory.GetFiles(dirName) 
                                         list.Add(path)
                                      Next
                                   End Sub  )
         tasks.Add(t)
      Next
      Task.WaitAll(tasks.ToArray())
      For Each t In tasks
         Console.WriteLine("Task {0} Status: {1}", t.Id, t.Status)
      Next   
      Console.WriteLine("Number of files read: {0}", list.Count)
   End Sub
End Module
' The example displays output like the following:
'       Task 1 Status: RanToCompletion
'       Task 2 Status: RanToCompletion
'       Number of files read: 23

설명

이 생성자는 작업을 만들고 시작 하는 작업을 구분 해야 하는 고급 시나리오 에서만 사용 해야 합니다.This constructor should only be used in advanced scenarios where it is required that the creation and starting of the task is separated.

인스턴스화하는 가장 일반적인 방법은이 생성자를 호출 하는 대신 한 Task 개체 및 작업은 정적 호출 하 여 시작 Task.Run(Action) 또는 TaskFactory.StartNew(Action) 메서드.Rather than calling this constructor, the most common way to instantiate a Task object and launch a task is by calling the static Task.Run(Action) or TaskFactory.StartNew(Action) method.

API의 소비자가 대기 해야 하는 작업을 수행 하기 위해 작업을 수행 하지 않은 작업이 필요한 경우에는 TaskCompletionSource<TResult>을 사용 해야 합니다.If a task with no action is needed just for the consumer of an API to have something to await, a TaskCompletionSource<TResult> should be used.

추가 정보

Task(Action, CancellationToken) Task(Action, CancellationToken) Task(Action, CancellationToken)

지정된 작업을 사용하여 새 TaskCancellationToken을 초기화합니다.Initializes a new Task with the specified action and CancellationToken.

public:
 Task(Action ^ action, System::Threading::CancellationToken cancellationToken);
public Task (Action action, System.Threading.CancellationToken cancellationToken);
new System.Threading.Tasks.Task : Action * System.Threading.CancellationToken -> System.Threading.Tasks.Task

매개 변수

action
Action Action Action Action

작업에서 실행할 코드를 나타내는 대리자입니다.The delegate that represents the code to execute in the task.

cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

작업이 관찰할 CancellationToken입니다.The CancellationToken that the new task will observe.

예외

action 인수가 null입니다.The action argument is null.

예제

다음 예제에서는 Task(Action, CancellationToken) C:\Windows\System32 디렉터리의 파일을 반복 하는 작업을 만드는 생성자입니다.The following example calls the Task(Action, CancellationToken) constructor to create a task that iterates the files in the C:\Windows\System32 directory. 람다 식 호출을 Parallel.ForEach 각 파일에 대 한 정보를 추가 하는 메서드를 List<T> 개체입니다.The lambda expression calls the Parallel.ForEach method to add information about each file to a List<T> object. 중첩 된 작업을 호출 하 여 각 분리를 Parallel.ForEach 루프 취소 토큰의 상태를 확인 하 고, 취소가 요청 된 경우 호출 된 CancellationToken.ThrowIfCancellationRequested 메서드.Each detached nested task invoked by the Parallel.ForEach loop checks the state of the cancellation token and, if cancellation is requested, calls the CancellationToken.ThrowIfCancellationRequested method. 합니다 CancellationToken.ThrowIfCancellationRequested 메서드가 throw를 OperationCanceledException 에서 처리 되는 예외를 catch 호출 호출 스레드를 차단 합니다 Task.Wait 메서드.The CancellationToken.ThrowIfCancellationRequested method throws an OperationCanceledException exception that is handled in a catch block when the calling thread calls the Task.Wait method. Start 메서드를 호출 하는 작업을 시작 합니다.The Start method is then called to start the task.

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

public class Example
{
   public static async Task Main()
   {
      var tokenSource = new CancellationTokenSource();
      var token = tokenSource.Token;
      var files = new List<Tuple<string, string, long, DateTime>>();
      
      var t = new Task(() => { string dir = "C:\\Windows\\System32\\";
                               object obj = new Object();
                               if (Directory.Exists(dir)) {
                                  Parallel.ForEach(Directory.GetFiles(dir),
                                  f => {
                                          if (token.IsCancellationRequested)
                                             token.ThrowIfCancellationRequested();
                                          var fi = new FileInfo(f);
                                          lock(obj) {
                                             files.Add(Tuple.Create(fi.Name, fi.DirectoryName, fi.Length, fi.LastWriteTimeUtc));          
                                          }
                                     });
                                }
                              } , token);
      t.Start();
      tokenSource.Cancel();
      try {
         await t; 
         Console.WriteLine("Retrieved information for {0} files.", files.Count);
      }
      catch (AggregateException e) {
         Console.WriteLine("Exception messages:");
         foreach (var ie in e.InnerExceptions)
            Console.WriteLine("   {0}: {1}", ie.GetType().Name, ie.Message);

         Console.WriteLine("\nTask status: {0}", t.Status);       
      }
      finally {
         tokenSource.Dispose();
      }
   }
}
// The example displays the following output:
//       Exception messages:
//          TaskCanceledException: A task was canceled.
//       
//       Task status: Canceled
Imports System.Collections.Generic
Imports System.IO
Imports System.Threading
Imports System.Threading.Tasks

Module Example
   Public Sub Main()
      Dim tokenSource As New CancellationTokenSource()
      Dim token As CancellationToken = tokenSource.Token
      Dim files As New List(Of Tuple(Of String, String, Long, Date))()
      Dim t As New Task(Sub()
                           Dim dir As String = "C:\Windows\System32\"
                           Dim obj As New Object()
                           If Directory.Exists(dir)Then
                              Parallel.ForEach(Directory.GetFiles(dir), 
                                 Sub(f)
                                    If token.IsCancellationRequested Then
                                       token.ThrowIfCancellationRequested()
                                    End If  
                                    Dim fi As New FileInfo(f)
                                    SyncLock(obj)
                                       files.Add(Tuple.Create(fi.Name, fi.DirectoryName, fi.Length, fi.LastWriteTimeUtc))          
                                    End SyncLock
                                 End Sub)
                           End If
                        End Sub, token)
      t.Start()
      tokenSource.Cancel()
      Try
         t.Wait() 
         Console.WriteLine("Retrieved information for {0} files.", files.Count)
      Catch e As AggregateException
         Console.WriteLine("Exception messages:")
         For Each ie As Exception In e.InnerExceptions
            Console.WriteLine("   {0}:{1}", ie.GetType().Name, ie.Message)
         Next
         Console.WriteLine()
         Console.WriteLine("Task status: {0}", t.Status)       
      Finally
         tokenSource.Dispose()
      End Try
   End Sub
End Module
' The example displays the following output:
'       Exception messages:
'          TaskCanceledException: A task was canceled.
'       
'       Task status: Canceled

설명

인스턴스화하는 가장 일반적인 방법은이 생성자를 호출 하는 대신 한 Task 개체 및 작업은 정적 호출 하 여 시작 Task.Run(Action, CancellationToken)TaskFactory.StartNew(Action, CancellationToken) 메서드.Rather than calling this constructor, the most common way to instantiate a Task object and launch a task is by calling the static Task.Run(Action, CancellationToken) and TaskFactory.StartNew(Action, CancellationToken) methods. 이 생성자에 의해 제공 되는 유일한 장점은 작업 호출에서 분리할 수 개체 인스턴스화 수 있다는 점입니다.The only advantage offered by this constructor is that it allows object instantiation to be separated from task invocation.

자세한 내용은 작업 병렬 처리 (작업 병렬 라이브러리) 하 고 관리 되는 스레드의 취소합니다.For more information, see Task Parallelism (Task Parallel Library) and Cancellation in Managed Threads.

Task(Action, TaskCreationOptions) Task(Action, TaskCreationOptions) Task(Action, TaskCreationOptions)

지정된 작업 및 만들기 옵션을 사용하여 새 Task를 초기화합니다.Initializes a new Task with the specified action and creation options.

public:
 Task(Action ^ action, System::Threading::Tasks::TaskCreationOptions creationOptions);
public Task (Action action, System.Threading.Tasks.TaskCreationOptions creationOptions);
new System.Threading.Tasks.Task : Action * System.Threading.Tasks.TaskCreationOptions -> System.Threading.Tasks.Task

매개 변수

action
Action Action Action Action

작업에서 실행할 코드를 나타내는 대리자입니다.The delegate that represents the code to execute in the task.

creationOptions
TaskCreationOptions TaskCreationOptions TaskCreationOptions TaskCreationOptions

작업의 동작을 사용자 지정하는 데 사용할 TaskCreationOptions입니다.The TaskCreationOptions used to customize the task's behavior.

예외

action 인수가 null입니다.The action argument is null.

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

설명

인스턴스화하는 가장 일반적인 방법은이 생성자를 호출 하는 대신 한 Task 개체 및 작업은 정적 호출 하 여 시작 TaskFactory.StartNew(Action, TaskCreationOptions) 메서드.Rather than calling this constructor, the most common way to instantiate a Task object and launch a task is by calling the static TaskFactory.StartNew(Action, TaskCreationOptions) method. 이 생성자에 의해 제공 되는 유일한 장점은 작업 호출에서 분리할 수 개체 인스턴스화 수 있다는 점입니다.The only advantage offered by this constructor is that it allows object instantiation to be separated from task invocation.

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

지정된 작업 및 상태를 사용하여 새 Task를 초기화합니다.Initializes a new Task with the specified action and state.

public:
 Task(Action<System::Object ^> ^ action, System::Object ^ state);
public Task (Action<object> action, object state);
new System.Threading.Tasks.Task : Action<obj> * obj -> System.Threading.Tasks.Task
Public Sub New (action As Action(Of Object), state As Object)

매개 변수

action
Action<Object>

작업에서 실행할 코드를 나타내는 대리자입니다.The delegate that represents the code to execute in the task.

state
Object Object Object Object

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

예외

action 인수가 null입니다.The action argument is null.

예제

다음 예제에서는 6 자로 단어 배열을 정의합니다.The following example defines an array of 6-letter words. 각 단어에 인수로 전달 됩니다 합니다 Task(Action<Object>, Object) 생성자 인 Action<T> 대리자 단어의 문자를 스크램블 다음 원래 단어 및 해당 암호화 된 버전을 표시 합니다.Each word is then passed as an argument to the Task(Action<Object>, Object) constructor, whose Action<T> delegate scrambles the characters in the word, then displays the original word and its scrambled version.

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

public class Example
{
   public static async Task Main()
   {
      var tasks = new List<Task>();
      Random rnd = new Random();
      Object lockObj = new Object();
      String[] words6 = { "reason", "editor", "rioter", "rental",
                          "senior", "regain", "ordain", "rained" };

      foreach (var word6 in words6) {
         Task t = new Task( (word) => { Char[] chars = word.ToString().ToCharArray();
                                        double[] order = new double[chars.Length];
                                        lock (lockObj) {
                                           for (int ctr = 0; ctr < order.Length; ctr++)
                                              order[ctr] = rnd.NextDouble();
                                           }
                                        Array.Sort(order, chars);
                                        Console.WriteLine("{0} --> {1}", word,
                                                          new String(chars));
                                      }, word6);
         t.Start();
         tasks.Add(t);
      }
      await Task.WhenAll(tasks.ToArray());
   }
}
// The example displays output like the following:
//    regain --> irnaeg
//    ordain --> rioadn
//    reason --> soearn
//    rained --> rinade
//    rioter --> itrore
//    senior --> norise
//    rental --> atnerl
//    editor --> oteird
Imports System.Collections.Generic
Imports System.Threading.Tasks

Module Example
   Public Sub Main()
      Dim tasks As New List(Of Task)()
      Dim rnd As New Random()
      Dim lockObj As New Object()
      Dim words6() As String = { "reason", "editor", "rioter", "rental",
                                 "senior", "regain", "ordain", "rained" }

      For Each word6 in words6
         Dim t As New Task( Sub(word)
                               Dim chars() As Char = word.ToString().ToCharArray()
                               Dim order(chars.Length - 1) As Double
                               SyncLock lockObj
                                  For ctr As Integer = 0 To order.Length - 1
                                     order(ctr) = rnd.NextDouble()
                                  Next
                               End SyncLock
                               Array.Sort(order, chars)
                               Console.WriteLine("{0} --> {1}", word,
                                                 New String(chars))
                            End Sub, word6)
         t.Start()
         tasks.Add(t)
      Next
      Task.WaitAll(tasks.ToArray())
   End Sub
End Module
' The example displays output like the following:
'       regain --> irnaeg
'       ordain --> rioadn
'       reason --> soearn
'       rained --> rinade
'       rioter --> itrore
'       senior --> norise
'       rental --> atnerl
'       editor --> oteird

설명

인스턴스화하는 가장 일반적인 방법은이 생성자를 호출 하는 대신 한 Task 개체 및 작업은 정적 호출 하 여 시작 TaskFactory.StartNew(Action<Object>, Object) 메서드.Rather than calling this constructor, the most common way to instantiate a Task object and launch a task is by calling the static TaskFactory.StartNew(Action<Object>, Object) method. 이 생성자에 의해 제공 되는 유일한 장점은 작업 호출에서 분리할 수 개체 인스턴스화 수 있다는 점입니다.The only advantage offered by this constructor is that it allows object instantiation to be separated from task invocation.

추가 정보

Task(Action, CancellationToken, TaskCreationOptions) Task(Action, CancellationToken, TaskCreationOptions) Task(Action, CancellationToken, TaskCreationOptions)

지정된 작업 및 만들기 옵션을 사용하여 새 Task를 초기화합니다.Initializes a new Task with the specified action and creation options.

public:
 Task(Action ^ action, System::Threading::CancellationToken cancellationToken, System::Threading::Tasks::TaskCreationOptions creationOptions);
public Task (Action action, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskCreationOptions creationOptions);
new System.Threading.Tasks.Task : Action * System.Threading.CancellationToken * System.Threading.Tasks.TaskCreationOptions -> System.Threading.Tasks.Task

매개 변수

action
Action Action Action Action

작업에서 실행할 코드를 나타내는 대리자입니다.The delegate that represents the code to execute in the task.

cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

새 작업이 관찰할 CancellationToken입니다.The CancellationToken that the new task will observe.

creationOptions
TaskCreationOptions TaskCreationOptions TaskCreationOptions TaskCreationOptions

작업의 동작을 사용자 지정하는 데 사용할 TaskCreationOptions입니다.The TaskCreationOptions used to customize the task's behavior.

예외

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

action 인수가 null입니다.The action argument is null.

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

설명

인스턴스화하는 가장 일반적인 방법은이 생성자를 호출 하는 대신 한 Task 개체 및 작업은 정적 호출 하 여 시작 TaskFactory.StartNew(Action, CancellationToken, TaskCreationOptions, TaskScheduler) 메서드.Rather than calling this constructor, the most common way to instantiate a Task object and launch a task is by calling the static TaskFactory.StartNew(Action, CancellationToken, TaskCreationOptions, TaskScheduler) method. 이 생성자에 의해 제공 되는 유일한 장점은 작업 호출에서 분리할 수 개체 인스턴스화 수 있다는 점입니다.The only advantage offered by this constructor is that it allows object instantiation to be separated from task invocation.

자세한 내용은 작업 병렬 처리 (작업 병렬 라이브러리) 하 고 작업 취소합니다.For more information, see Task Parallelism (Task Parallel Library) and Task Cancellation.

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

지정된 작업, 상태 및 옵션을 사용하여 새 Task를 초기화합니다.Initializes a new Task with the specified action, state, and options.

public:
 Task(Action<System::Object ^> ^ action, System::Object ^ state, System::Threading::CancellationToken cancellationToken);
public Task (Action<object> action, object state, System.Threading.CancellationToken cancellationToken);
new System.Threading.Tasks.Task : Action<obj> * obj * System.Threading.CancellationToken -> System.Threading.Tasks.Task

매개 변수

action
Action<Object>

작업에서 실행할 코드를 나타내는 대리자입니다.The delegate that represents the code to execute in the task.

state
Object Object Object Object

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

cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

새 작업이 관찰할 CancellationToken입니다.The CancellationToken that the new task will observe.

예외

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

action 인수가 null입니다.The action argument is null.

설명

인스턴스화하는 가장 일반적인 방법은이 생성자를 호출 하는 대신 한 Task 개체 및 작업은 정적 호출 하 여 시작 TaskFactory.StartNew(Action<Object>, Object, CancellationToken) 메서드.Rather than calling this constructor, the most common way to instantiate a Task object and launch a task is by calling the static TaskFactory.StartNew(Action<Object>, Object, CancellationToken) method. 이 생성자에 의해 제공 되는 유일한 장점은 작업 호출에서 분리할 수 개체 인스턴스화 수 있다는 점입니다.The only advantage offered by this constructor is that it allows object instantiation to be separated from task invocation.

Task(Action<Object>, Object, TaskCreationOptions) Task(Action<Object>, Object, TaskCreationOptions) Task(Action<Object>, Object, TaskCreationOptions) Task(Action<Object>, Object, TaskCreationOptions)

지정된 작업, 상태 및 옵션을 사용하여 새 Task를 초기화합니다.Initializes a new Task with the specified action, state, and options.

public:
 Task(Action<System::Object ^> ^ action, System::Object ^ state, System::Threading::Tasks::TaskCreationOptions creationOptions);
public Task (Action<object> action, object state, System.Threading.Tasks.TaskCreationOptions creationOptions);
new System.Threading.Tasks.Task : Action<obj> * obj * System.Threading.Tasks.TaskCreationOptions -> System.Threading.Tasks.Task
Public Sub New (action As Action(Of Object), state As Object, creationOptions As TaskCreationOptions)

매개 변수

action
Action<Object>

작업에서 실행할 코드를 나타내는 대리자입니다.The delegate that represents the code to execute in the task.

state
Object Object Object Object

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

creationOptions
TaskCreationOptions TaskCreationOptions TaskCreationOptions TaskCreationOptions

작업의 동작을 사용자 지정하는 데 사용할 TaskCreationOptions입니다.The TaskCreationOptions used to customize the task's behavior.

예외

action 인수가 null입니다.The action argument is null.

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

설명

인스턴스화하는 가장 일반적인 방법은이 생성자를 호출 하는 대신 한 Task 개체 및 작업은 정적 호출 하 여 시작 TaskFactory.StartNew(Action<Object>, Object, TaskCreationOptions) 메서드.Rather than calling this constructor, the most common way to instantiate a Task object and launch a task is by calling the static TaskFactory.StartNew(Action<Object>, Object, TaskCreationOptions) method. 이 생성자에 의해 제공 되는 유일한 장점은 작업 호출에서 분리할 수 개체 인스턴스화 수 있다는 점입니다.The only advantage offered by this constructor is that it allows object instantiation to be separated from task invocation.

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

지정된 작업, 상태 및 옵션을 사용하여 새 Task를 초기화합니다.Initializes a new Task with the specified action, state, and options.

public:
 Task(Action<System::Object ^> ^ action, System::Object ^ state, System::Threading::CancellationToken cancellationToken, System::Threading::Tasks::TaskCreationOptions creationOptions);
public Task (Action<object> action, object state, System.Threading.CancellationToken cancellationToken, System.Threading.Tasks.TaskCreationOptions creationOptions);
new System.Threading.Tasks.Task : Action<obj> * obj * System.Threading.CancellationToken * System.Threading.Tasks.TaskCreationOptions -> System.Threading.Tasks.Task

매개 변수

action
Action<Object>

작업에서 실행할 코드를 나타내는 대리자입니다.The delegate that represents the code to execute in the task.

state
Object Object Object Object

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

cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

새 작업이 관찰할 CancellationToken입니다.The CancellationToken that the new task will observe.

creationOptions
TaskCreationOptions TaskCreationOptions TaskCreationOptions TaskCreationOptions

작업의 동작을 사용자 지정하는 데 사용할 TaskCreationOptions입니다.The TaskCreationOptions used to customize the task's behavior.

예외

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

action 인수가 null입니다.The action argument is null.

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

설명

인스턴스화하는 가장 일반적인 방법은이 생성자를 호출 하는 대신 한 Task 개체 및 작업은 정적 호출 하 여 시작 TaskFactory.StartNew(Action<Object>, Object, CancellationToken, TaskCreationOptions, TaskScheduler) 메서드.Rather than calling this constructor, the most common way to instantiate a Task object and launch a task is by calling the static TaskFactory.StartNew(Action<Object>, Object, CancellationToken, TaskCreationOptions, TaskScheduler) method. 이 생성자에 의해 제공 되는 유일한 장점은 작업 호출에서 분리할 수 개체 인스턴스화 수 있다는 점입니다.The only advantage offered by this constructor is that it allows object instantiation to be separated from task invocation.

적용 대상