Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides support for parallel loops and regions.
public ref class Parallel abstract sealed
public static class Parallel
type Parallel = class
Public Class Parallel
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
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.
For(Int32, Int32, Action<Int32,Parallel |
Executes a |
For(Int32, Int32, Action<Int32>) |
Executes a |
For(Int32, Int32, Parallel |
Executes a |
For(Int32, Int32, Parallel |
Executes a |
For(Int64, Int64, Action<Int64,Parallel |
Executes a |
For(Int64, Int64, Action<Int64>) |
Executes a |
For(Int64, Int64, Parallel |
Executes a |
For(Int64, Int64, Parallel |
Executes a |
For<TLocal>(Int32, Int32, Func<TLocal>, Func<Int32,Parallel |
Executes a |
For<TLocal>(Int32, Int32, Parallel |
Executes a |
For<TLocal>(Int64, Int64, Func<TLocal>, Func<Int64,Parallel |
Executes a |
For<TLocal>(Int64, Int64, Parallel |
Executes a |
For |
Executes a for loop in which iterations may run in parallel. |
For |
Executes a for loop in which iterations may run in parallel. |
For |
Executes a for loop in which iterations may run in parallel. |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
For |
Executes a |
Invoke(Action[]) |
Executes each of the provided actions, possibly in parallel. |
Invoke(Parallel |
Executes each of the provided actions, possibly in parallel, unless the operation is cancelled by the user. |
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
UWP | 10.0 |
All public and protected members of Parallel are thread-safe and may be used concurrently from multiple threads.
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in