Parallel Class
Definition
Provides support for parallel loops and regions.
public static class Parallel
- Inheritance
-
Parallel
Inherited Members
System.Object
Examples
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.
}
}
Imports System.Threading.Tasks
Module Module1
Sub Main()
Dim N As Integer = 1000
' Using a named method
Parallel.For(0, N, AddressOf Method2)
' Using a lambda expression.
Parallel.For(0, N, Sub(i)
' Do Work
End Sub)
End Sub
Sub Method2(ByVal i As Integer)
' Do work.
End Sub
End Module
Remarks
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.
Methods
| For(Int32, Int32, Action<Int32,ParallelLoopState>) |
Executes a |
| For(Int32, Int32, Action<Int32>) |
Executes a |
| For(Int64, Int64, Action<Int64,ParallelLoopState>) |
Executes a |
| For(Int64, Int64, Action<Int64>) |
Executes a |
| For(Int32, Int32, ParallelOptions, Action<Int32,ParallelLoopState>) |
Executes a |
| For(Int32, Int32, ParallelOptions, Action<Int32>) |
Executes a |
| For(Int64, Int64, ParallelOptions, Action<Int64,ParallelLoopState>) |
Executes a |
| For(Int64, Int64, ParallelOptions, Action<Int64>) |
Executes a |
| For<TLocal>(Int64, Int64, ParallelOptions, Func<TLocal>, Func<Int64,ParallelLoopState,TLocal,TLocal>, Action<TLocal>) |
Executes a |
| For<TLocal>(Int32, Int32, ParallelOptions, Func<TLocal>, Func<Int32,ParallelLoopState,TLocal,TLocal>, Action<TLocal>) |
Executes a |
| For<TLocal>(Int32, Int32, Func<TLocal>, Func<Int32,ParallelLoopState,TLocal,TLocal>, Action<TLocal>) |
Executes a |
| For<TLocal>(Int64, Int64, Func<TLocal>, Func<Int64,ParallelLoopState,TLocal,TLocal>, Action<TLocal>) |
Executes a |
| ForEach<TSource,TLocal>(IEnumerable<TSource>, ParallelOptions, Func<TLocal>, Func<TSource,ParallelLoopState,TLocal,TLocal>, Action<TLocal>) |
Executes a |
| ForEach<TSource,TLocal>(IEnumerable<TSource>, ParallelOptions, Func<TLocal>, Func<TSource,ParallelLoopState,Int64,TLocal,TLocal>, Action<TLocal>) |
Executes a |
| ForEach<TSource,TLocal>(Partitioner<TSource>, ParallelOptions, Func<TLocal>, Func<TSource,ParallelLoopState,TLocal,TLocal>, Action<TLocal>) |
Executes a |
| ForEach<TSource,TLocal>(OrderablePartitioner<TSource>, ParallelOptions, Func<TLocal>, Func<TSource,ParallelLoopState,Int64,TLocal,TLocal>, Action<TLocal>) |
Executes a |
| ForEach<TSource,TLocal>(IEnumerable<TSource>, Func<TLocal>, Func<TSource,ParallelLoopState,TLocal,TLocal>, Action<TLocal>) |
Executes a |
| ForEach<TSource,TLocal>(IEnumerable<TSource>, Func<TLocal>, Func<TSource,ParallelLoopState,Int64,TLocal,TLocal>, Action<TLocal>) |
Executes a |
| ForEach<TSource,TLocal>(Partitioner<TSource>, Func<TLocal>, Func<TSource,ParallelLoopState,TLocal,TLocal>, Action<TLocal>) |
Executes a |
| ForEach<TSource,TLocal>(OrderablePartitioner<TSource>, Func<TLocal>, Func<TSource,ParallelLoopState,Int64,TLocal,TLocal>, Action<TLocal>) |
Executes a |
| ForEach<TSource>(IEnumerable<TSource>, ParallelOptions, Action<TSource>) |
Executes a |
| ForEach<TSource>(IEnumerable<TSource>, ParallelOptions, Action<TSource,ParallelLoopState>) |
Executes a |
| ForEach<TSource>(IEnumerable<TSource>, Action<TSource,ParallelLoopState>) |
Executes a |
| ForEach<TSource>(Partitioner<TSource>, ParallelOptions, Action<TSource>) |
Executes a |
| ForEach<TSource>(Partitioner<TSource>, ParallelOptions, Action<TSource,ParallelLoopState>) |
Executes a |
| ForEach<TSource>(OrderablePartitioner<TSource>, ParallelOptions, Action<TSource,ParallelLoopState,Int64>) |
Executes a |
| ForEach<TSource>(IEnumerable<TSource>, Action<TSource>) |
Executes a |
| ForEach<TSource>(IEnumerable<TSource>, Action<TSource,ParallelLoopState,Int64>) |
Executes a |
| ForEach<TSource>(Partitioner<TSource>, Action<TSource>) |
Executes a |
| ForEach<TSource>(Partitioner<TSource>, Action<TSource,ParallelLoopState>) |
Executes a |
| ForEach<TSource>(OrderablePartitioner<TSource>, Action<TSource,ParallelLoopState,Int64>) |
Executes a |
| ForEach<TSource>(IEnumerable<TSource>, ParallelOptions, Action<TSource,ParallelLoopState,Int64>) |
Executes a |
| Invoke(Action[]) |
Executes each of the provided actions, possibly in parallel. |
| Invoke(ParallelOptions, Action[]) |
Executes each of the provided actions, possibly in parallel, unless the operation is cancelled by the user. |
Thread Safety
All public and protected members of Parallel are thread-safe and may be used concurrently from multiple threads.