Parallel.Invoke 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
각각의 제공된 동작을 가능하면 병렬로 실행합니다.
오버로드
| Invoke(Action[]) |
각각의 제공된 동작을 가능하면 병렬로 실행합니다. |
| Invoke(ParallelOptions, Action[]) |
사용자가 작업을 취소하지 않는다면 제공된 각 작업을 가능한 한 병렬로 실행합니다. |
Invoke(Action[])
각각의 제공된 동작을 가능하면 병렬로 실행합니다.
public:
static void Invoke(... cli::array <Action ^> ^ actions);
public static void Invoke (params Action[] actions);
static member Invoke : Action[] -> unit
Public Shared Sub Invoke (ParamArray actions As Action())
매개 변수
예외
actions 인수가 null인 경우
actions 배열에 있는 모든 작업이 예외를 throw하는 경우 throw되는 예외입니다.
actions 배열에 null 요소가 포함되어 있습니다.
예제
이 예제에서는 다른 메서드, 익명 대리자 및 람다 식에서 메서드를 사용하는 Invoke 방법을 보여 줍니다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
class ParallelInvokeDemo
{
// Demonstrated features:
// Parallel.Invoke()
// Expected results:
// The threads on which each task gets executed may be different.
// The thread assignments may be different in different executions.
// The tasks may get executed in any order.
// Documentation:
// http://msdn.microsoft.com/library/dd783942(VS.100).aspx
static void Main()
{
try
{
Parallel.Invoke(
BasicAction, // Param #0 - static method
() => // Param #1 - lambda expression
{
Console.WriteLine("Method=beta, Thread={0}", Thread.CurrentThread.ManagedThreadId);
},
delegate() // Param #2 - in-line delegate
{
Console.WriteLine("Method=gamma, Thread={0}", Thread.CurrentThread.ManagedThreadId);
}
);
}
// No exception is expected in this example, but if one is still thrown from a task,
// it will be wrapped in AggregateException and propagated to the main thread.
catch (AggregateException e)
{
Console.WriteLine("An action has thrown an exception. THIS WAS UNEXPECTED.\n{0}", e.InnerException.ToString());
}
}
static void BasicAction()
{
Console.WriteLine("Method=alpha, Thread={0}", Thread.CurrentThread.ManagedThreadId);
}
}
Imports System.Threading
Imports System.Threading.Tasks
Module InvokeDemo
' Demonstrated features:
' Parallel.Invoke()
' Expected results:
' The threads on which each task gets executed may be different.
' The thread assignments may be different in different executions.
' The tasks may get executed in any order.
' Documentation:
' http://msdn.microsoft.com/library/dd783942(VS.100).aspx
Private Sub Main()
Try
' Param #0 - static method
Parallel.Invoke(AddressOf BasicAction,
Sub()
' Param #1 - lambda expression
Console.WriteLine("Method=beta, Thread={0}", Thread.CurrentThread.ManagedThreadId)
End Sub,
Sub()
' Param #2 - in-line delegate
Console.WriteLine("Method=gamma, Thread={0}", Thread.CurrentThread.ManagedThreadId)
End Sub)
Catch e As AggregateException
' No exception is expected in this example, but if one is still thrown from a task,
' it will be wrapped in AggregateException and propagated to the main thread.
Console.WriteLine("An action has thrown an exception. THIS WAS UNEXPECTED." & vbLf & "{0}", e.InnerException.ToString())
End Try
End Sub
Private Sub BasicAction()
Console.WriteLine("Method=alpha, Thread={0}", Thread.CurrentThread.ManagedThreadId)
End Sub
End Module
설명
이 메서드는 잠재적으로 병렬로 작업 집합을 실행하는 데 사용할 수 있습니다.
작업이 실행되는 순서 또는 병렬로 실행되는지 여부에 대한 보장은 없습니다. 이 메서드는 정상 또는 예외 종료로 인해 완료가 발생하는지 여부에 관계없이 제공된 각 작업이 완료될 때까지 반환되지 않습니다.
자세한 내용은 방법: Parallel.Invoke를 사용하여 병렬 작업 실행을 참조하세요.
적용 대상
Invoke(ParallelOptions, Action[])
사용자가 작업을 취소하지 않는다면 제공된 각 작업을 가능한 한 병렬로 실행합니다.
public:
static void Invoke(System::Threading::Tasks::ParallelOptions ^ parallelOptions, ... cli::array <Action ^> ^ actions);
public static void Invoke (System.Threading.Tasks.ParallelOptions parallelOptions, params Action[] actions);
static member Invoke : System.Threading.Tasks.ParallelOptions * Action[] -> unit
Public Shared Sub Invoke (parallelOptions As ParallelOptions, ParamArray actions As Action())
매개 변수
- parallelOptions
- ParallelOptions
이 작업의 동작을 구성하는 개체입니다.
- actions
- Action[]
실행할 동작의 배열입니다.
예외
parallelOptions의 CancellationToken이 설정됩니다.
actions 배열에 있는 모든 작업이 예외를 throw하는 경우 throw되는 예외입니다.
actions 배열에 null 요소가 포함되어 있습니다.
parallelOptions의 CancellationTokenSource과 연결된 CancellationToken가 삭제되었습니다.
설명
이 메서드는 잠재적으로 병렬로 작업 집합을 실행하는 데 사용할 수 있습니다. 구조와 함께 전달된 취소 토큰을 ParallelOptions 사용하면 호출자가 전체 작업을 취소할 수 있습니다. 자세한 내용은 관리되는 스레드의 취소를 참조하세요.
작업이 실행되는 순서 또는 병렬로 실행되는지 여부에 대한 보장은 없습니다. 이 메서드는 정상 또는 예외 종료로 인해 완료가 발생하는지 여부에 관계없이 제공된 각 작업이 완료될 때까지 반환되지 않습니다.
자세한 내용은 방법: Parallel.Invoke를 사용하여 병렬 작업 실행을 참조하세요.