Parallel.Invoke 메서드

정의

제공된 각 작업을 병렬로 실행합니다.

오버로드

Name Description
Invoke(Action[])

제공된 각 작업을 병렬로 실행합니다.

Invoke(ParallelOptions, Action[])

사용자가 작업을 취소하지 않는 한 제공된 각 작업을 병렬로 실행합니다.

Invoke(Action[])

Source:
Parallel.cs
Source:
Parallel.cs
Source:
Parallel.cs
Source:
Parallel.cs
Source:
Parallel.cs

제공된 각 작업을 병렬로 실행합니다.

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
Action[]

실행할 배열입니다 Action .

예외

인수는 actions .입니다 null.

배열의 모든 작업이 예외를 throw할 actions 때 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[])

Source:
Parallel.cs
Source:
Parallel.cs
Source:
Parallel.cs
Source:
Parallel.cs
Source:
Parallel.cs

사용자가 작업을 취소하지 않는 한 제공된 각 작업을 병렬로 실행합니다.

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[]

실행할 작업의 배열입니다.

예외

CancellationToken in은 parallelOptions 설정됩니다.

인수는 actions .입니다 null.

-또는-

인수는 parallelOptions .입니다 null.

배열의 모든 작업이 예외를 throw할 actions 때 throw되는 예외입니다.

배열에 actions 요소가 포함됩니다 null .

CancellationTokenSource in CancellationTokenparallelOptions 연결된 값이 삭제되었습니다.

설명

이 메서드는 잠재적으로 병렬로 작업 집합을 실행하는 데 사용할 수 있습니다. 구조와 함께 전달된 취소 토큰을 ParallelOptions 사용하면 호출자가 전체 작업을 취소할 수 있습니다. 자세한 내용은 관리되는 스레드에서 취소을 참조하세요.

작업이 실행되는 순서 또는 병렬로 실행되는지 여부에 대한 보장은 없습니다. 이 메서드는 정상 또는 예외 종료로 인해 완료가 발생하는지 여부에 관계없이 제공된 각 작업이 완료될 때까지 반환되지 않습니다.

자세한 내용은 방법: Parallel.Invoke를 사용하여 병렬 작업 실행참조하세요.

적용 대상