3 out of 3 rated this helpful - Rate this topic

Parallel Class

Provides support for parallel loops and regions.

System.Object
  System.Threading.Tasks.Parallel

Namespace:  System.Threading.Tasks
Assembly:  mscorlib (in mscorlib.dll)
[HostProtectionAttribute(SecurityAction.LinkDemand, Synchronization = true, 
	ExternalThreading = true)]
public static class Parallel
  NameDescription
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFor(Int32, Int32, Action<Int32>)Executes a for (For in Visual Basic) loop in which iterations may run in parallel.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFor(Int32, Int32, Action<Int32, ParallelLoopState>)Executes a for (For in Visual Basic) loop in which iterations may run in parallel and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFor(Int64, Int64, Action<Int64>)Executes a for (For in Visual Basic) loop with 64-bit indexes in which iterations may run in parallel.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFor(Int64, Int64, Action<Int64, ParallelLoopState>)Executes a for (For in Visual Basic) loop with 64-bit indexes in which iterations may run in parallel and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFor(Int32, Int32, ParallelOptions, Action<Int32>)Executes a for (For in Visual Basic) loop in which iterations may run in parallel and loop options can be configured.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFor(Int32, Int32, ParallelOptions, Action<Int32, ParallelLoopState>)Executes a for (For in Visual Basic) loop in which iterations may run in parallel, loop options can be configured, and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFor(Int64, Int64, ParallelOptions, Action<Int64>)Executes a for (For in Visual Basic) loop with 64-bit indexes in which iterations may run in parallel and loop options can be configured.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFor(Int64, Int64, ParallelOptions, Action<Int64, ParallelLoopState>)Executes a for (For in Visual Basic) loop with 64-bit indexes in which iterations may run in parallel, loop options can be configured, and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFor<TLocal>(Int32, Int32, Func<TLocal>, Func<Int32, ParallelLoopState, TLocal, TLocal>, Action<TLocal>)Executes a for (For in Visual Basic) loop with thread-local data in which iterations may run in parallel, and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFor<TLocal>(Int64, Int64, Func<TLocal>, Func<Int64, ParallelLoopState, TLocal, TLocal>, Action<TLocal>)Executes a for (For in Visual Basic) loop with 64-bit indexes and thread-local data in which iterations may run in parallel, and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFor<TLocal>(Int32, Int32, ParallelOptions, Func<TLocal>, Func<Int32, ParallelLoopState, TLocal, TLocal>, Action<TLocal>)Executes a for (For in Visual Basic) loop with thread-local data in which iterations may run in parallel, loop options can be configured, and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsFor<TLocal>(Int64, Int64, ParallelOptions, Func<TLocal>, Func<Int64, ParallelLoopState, TLocal, TLocal>, Action<TLocal>)Executes a for (For in Visual Basic) loop with 64-bit indexes and thread-local data in which iterations may run in parallel, loop options can be configured, and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsForEach<TSource>(IEnumerable<TSource>, Action<TSource>)Executes a foreach (For Each in Visual Basic) operation on an IEnumerable in which iterations may run in parallel.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsForEach<TSource>(IEnumerable<TSource>, Action<TSource, ParallelLoopState>)Executes a foreach (For Each in Visual Basic) operation on an IEnumerable in which iterations may run in parallel, and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsForEach<TSource>(IEnumerable<TSource>, Action<TSource, ParallelLoopState, Int64>)Executes a foreach (For Each in Visual Basic) operation with 64-bit indexes on an IEnumerable in which iterations may run in parallel, and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsForEach<TSource>(OrderablePartitioner<TSource>, Action<TSource, ParallelLoopState, Int64>)Executes a foreach (For Each in Visual Basic) operation on a OrderablePartitioner<TSource> in which iterations may run in parallel and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsForEach<TSource>(Partitioner<TSource>, Action<TSource>)Executes a foreach (For Each in Visual Basic) operation on a Partitioner in which iterations may run in parallel.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsForEach<TSource>(Partitioner<TSource>, Action<TSource, ParallelLoopState>)Executes a foreach (For Each in Visual Basic) operation on a System.Collections.Concurrent.Partitioner in which iterations may run in parallel, and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsForEach<TSource>(IEnumerable<TSource>, ParallelOptions, Action<TSource>)Executes a foreach (For Each in Visual Basic) operation on an IEnumerable in which iterations may run in parallel and loop options can be configured.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsForEach<TSource>(IEnumerable<TSource>, ParallelOptions, Action<TSource, ParallelLoopState>)Executes a foreach (For Each in Visual Basic) operation on an IEnumerable in which iterations may run in parallel, loop options can be configured, and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsForEach<TSource>(IEnumerable<TSource>, ParallelOptions, Action<TSource, ParallelLoopState, Int64>)Executes a foreach (For Each in Visual Basic) operation with 64-bit indexes on an IEnumerable in which iterations may run in parallel, loop options can be configured, and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsForEach<TSource>(OrderablePartitioner<TSource>, ParallelOptions, Action<TSource, ParallelLoopState, Int64>)Executes a foreach (For Each in Visual Basic) operation on a OrderablePartitioner<TSource> in which iterations may run in parallel, loop options can be configured, and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsForEach<TSource>(Partitioner<TSource>, ParallelOptions, Action<TSource>)Executes a foreach (For Each in Visual Basic) operation on a Partitioner in which iterations may run in parallel and loop options can be configured.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsForEach<TSource>(Partitioner<TSource>, ParallelOptions, Action<TSource, ParallelLoopState>)Executes a foreach (For Each in Visual Basic) operation on a Partitioner in which iterations may run in parallel, loop options can be configured, and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsForEach<TSource, TLocal>(IEnumerable<TSource>, Func<TLocal>, Func<TSource, ParallelLoopState, TLocal, TLocal>, Action<TLocal>)Executes a foreach (For Each in Visual Basic) operation with thread-local data on an IEnumerable in which iterations may run in parallel, and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsForEach<TSource, TLocal>(IEnumerable<TSource>, Func<TLocal>, Func<TSource, ParallelLoopState, Int64, TLocal, TLocal>, Action<TLocal>)Executes a foreach (For Each in Visual Basic) operation with thread-local data on an IEnumerable in which iterations may run in parallel and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsForEach<TSource, TLocal>(OrderablePartitioner<TSource>, Func<TLocal>, Func<TSource, ParallelLoopState, Int64, TLocal, TLocal>, Action<TLocal>)Executes a foreach (For Each in Visual Basic) operation with thread-local data on a OrderablePartitioner<TSource> in which iterations may run in parallel, loop options can be configured, and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsForEach<TSource, TLocal>(Partitioner<TSource>, Func<TLocal>, Func<TSource, ParallelLoopState, TLocal, TLocal>, Action<TLocal>)Executes a foreach (For Each in Visual Basic) operation with thread-local data on a Partitioner in which iterations may run in parallel and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsForEach<TSource, TLocal>(IEnumerable<TSource>, ParallelOptions, Func<TLocal>, Func<TSource, ParallelLoopState, TLocal, TLocal>, Action<TLocal>)Executes a foreach (For Each in Visual Basic) operation with thread-local data on an IEnumerable in which iterations may run in parallel, loop options can be configured, and the state of the loop can be monitored and manipulated..
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsForEach<TSource, TLocal>(IEnumerable<TSource>, ParallelOptions, Func<TLocal>, Func<TSource, ParallelLoopState, Int64, TLocal, TLocal>, Action<TLocal>)Executes a foreach (For Each in Visual Basic) operation with thread-local data and 64-bit indexes on an IEnumerable in which iterations may run in parallel, loop options can be configured, and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsForEach<TSource, TLocal>(OrderablePartitioner<TSource>, ParallelOptions, Func<TLocal>, Func<TSource, ParallelLoopState, Int64, TLocal, TLocal>, Action<TLocal>)Executes a foreach (For Each in Visual Basic) operation with 64-bit indexes and with thread-local data on a OrderablePartitioner<TSource> in which iterations may run in parallel , loop options can be configured, and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsForEach<TSource, TLocal>(Partitioner<TSource>, ParallelOptions, Func<TLocal>, Func<TSource, ParallelLoopState, TLocal, TLocal>, Action<TLocal>)Executes a foreach (For Each in Visual Basic) operation with thread-local data on a Partitioner in which iterations may run in parallel, loop options can be configured, and the state of the loop can be monitored and manipulated.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsInvoke(Action[])Executes each of the provided actions, possibly in parallel.
Public methodStatic memberSupported by Portable Class LibrarySupported in .NET for Windows Store appsInvoke(ParallelOptions, Action[])Executes each of the provided actions, possibly in parallel, unless the operation is cancelled by the user.
Top

The Parallel class provides library-based data parallel replacements for common operations such as for loops, for each loops, and execution of a set of statements.

NoteNote

The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: Synchronization | ExternalThreading. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

This example demonstrates several approaches to implementing a parallel loop using multiple language constructs.

using System.Threading.Tasks;   
class Test
{
    static int N = 1000;

    static void TestMethod()
    {
        // Using a named method.
        Parallel.For(0, N, Method2);

        // Using an anonymous method.
        Parallel.For(0, N, delegate(int i)
        {
            // Do Work.
        });

        // Using a lambda expression.
        Parallel.For(0, N, i =>
        {
            // Do Work.
        });
    }

    static void Method2(int i)
    {
        // Do work.
    }
}

.NET Framework

Supported in: 4.5.1, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

All public and protected members of Parallel are thread-safe and may be used concurrently from multiple threads.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.