Parallel.Invoke Method (Action[])

.NET Framework 4.6 and 4.5

Executes each of the provided actions, possibly in parallel.

Namespace:  System.Threading.Tasks
Assemblies:   mscorlib (in mscorlib.dll)
  System.Threading.Tasks.Parallel (in System.Threading.Tasks.Parallel.dll)

public static void Invoke(
	params Action[] actions


Type: System.Action[]

An array of Action to execute.


The actions argument is null.


The exception that is thrown when any action in the actions array throws an exception.


The actions array contains a null element.

This method can be used to execute a set of operations, potentially in parallel.

No guarantees are made about the order in which the operations execute or whether they execute in parallel. This method does not return until each of the provided operations has completed, regardless of whether completion occurs due to normal or exceptional termination.

For more information, see How to: Use Parallel.Invoke to Execute Parallel Operations.

This example demonstrates how to use the Invokemethod with other methods, anonymous delegates, and lambda expressions.

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: 
        static void Main()
                    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);


.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4

.NET for Windows Phone apps

Supported in: Windows Phone 8.1

Portable Class Library

Supported in: Portable Class Library
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft