Parallel Klasse
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Bietet Unterstützung für parallele Schleifen und Regionen.
public ref class Parallel abstract sealed
public static class Parallel
type Parallel = class
Public Class Parallel
- Vererbung
-
Parallel
Beispiele
In diesem Beispiel werden verschiedene Ansätze zum Implementieren einer parallelen Schleife mithilfe mehrerer Sprachkonstrukte veranschaulicht.
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
Hinweise
Die Parallel Klasse stellt bibliotheksbasierte Daten parallele Ersetzungen für allgemeine Vorgänge bereit, z. B. für Schleifen, für jede Schleife und die Ausführung einer Reihe von Anweisungen.
Methoden
| Name | Beschreibung |
|---|---|
| For(Int32, Int32, Action<Int32,ParallelLoopState>) |
Führt eine |
| For(Int32, Int32, Action<Int32>) |
Führt eine |
| For(Int32, Int32, ParallelOptions, Action<Int32,ParallelLoopState>) |
Führt eine |
| For(Int32, Int32, ParallelOptions, Action<Int32>) |
Führt eine |
| For(Int64, Int64, Action<Int64,ParallelLoopState>) |
Führt eine |
| For(Int64, Int64, Action<Int64>) |
Führt eine |
| For(Int64, Int64, ParallelOptions, Action<Int64,ParallelLoopState>) |
Führt eine |
| For(Int64, Int64, ParallelOptions, Action<Int64>) |
Führt eine |
| For<TLocal>(Int32, Int32, Func<TLocal>, Func<Int32,ParallelLoopState,TLocal,TLocal>, Action<TLocal>) |
Führt eine |
| For<TLocal>(Int32, Int32, ParallelOptions, Func<TLocal>, Func<Int32,ParallelLoopState,TLocal,TLocal>, Action<TLocal>) |
Führt eine |
| For<TLocal>(Int64, Int64, Func<TLocal>, Func<Int64,ParallelLoopState,TLocal,TLocal>, Action<TLocal>) |
Führt eine |
| For<TLocal>(Int64, Int64, ParallelOptions, Func<TLocal>, Func<Int64,ParallelLoopState,TLocal,TLocal>, Action<TLocal>) |
Führt eine |
| ForEach<TSource,TLocal>(IEnumerable<TSource>, Func<TLocal>, Func<TSource,ParallelLoopState,Int64,TLocal,TLocal>, Action<TLocal>) |
Führt einen |
| ForEach<TSource,TLocal>(IEnumerable<TSource>, Func<TLocal>, Func<TSource,ParallelLoopState,TLocal,TLocal>, Action<TLocal>) |
Führt einen |
| ForEach<TSource,TLocal>(IEnumerable<TSource>, ParallelOptions, Func<TLocal>, Func<TSource,ParallelLoopState,Int64,TLocal,TLocal>, Action<TLocal>) |
Führt einen |
| ForEach<TSource,TLocal>(IEnumerable<TSource>, ParallelOptions, Func<TLocal>, Func<TSource,ParallelLoopState,TLocal,TLocal>, Action<TLocal>) |
Führt einen |
| ForEach<TSource,TLocal>(OrderablePartitioner<TSource>, Func<TLocal>, Func<TSource,ParallelLoopState,Int64,TLocal,TLocal>, Action<TLocal>) |
Führt einen |
| ForEach<TSource,TLocal>(OrderablePartitioner<TSource>, ParallelOptions, Func<TLocal>, Func<TSource,ParallelLoopState,Int64,TLocal,TLocal>, Action<TLocal>) |
Führt einen |
| ForEach<TSource,TLocal>(Partitioner<TSource>, Func<TLocal>, Func<TSource,ParallelLoopState,TLocal,TLocal>, Action<TLocal>) |
Führt einen |
| ForEach<TSource,TLocal>(Partitioner<TSource>, ParallelOptions, Func<TLocal>, Func<TSource,ParallelLoopState,TLocal,TLocal>, Action<TLocal>) |
Führt einen |
| ForEach<TSource>(IEnumerable<TSource>, Action<TSource,ParallelLoopState,Int64>) |
Führt einen |
| ForEach<TSource>(IEnumerable<TSource>, Action<TSource,ParallelLoopState>) |
Führt einen |
| ForEach<TSource>(IEnumerable<TSource>, Action<TSource>) |
Führt einen |
| ForEach<TSource>(IEnumerable<TSource>, ParallelOptions, Action<TSource,ParallelLoopState,Int64>) |
Führt einen |
| ForEach<TSource>(IEnumerable<TSource>, ParallelOptions, Action<TSource,ParallelLoopState>) |
Führt einen |
| ForEach<TSource>(IEnumerable<TSource>, ParallelOptions, Action<TSource>) |
Führt einen |
| ForEach<TSource>(OrderablePartitioner<TSource>, Action<TSource,ParallelLoopState,Int64>) |
Führt einen |
| ForEach<TSource>(OrderablePartitioner<TSource>, ParallelOptions, Action<TSource,ParallelLoopState,Int64>) |
Führt einen |
| ForEach<TSource>(Partitioner<TSource>, Action<TSource,ParallelLoopState>) |
Führt einen |
| ForEach<TSource>(Partitioner<TSource>, Action<TSource>) |
Führt einen |
| ForEach<TSource>(Partitioner<TSource>, ParallelOptions, Action<TSource,ParallelLoopState>) |
Führt einen |
| ForEach<TSource>(Partitioner<TSource>, ParallelOptions, Action<TSource>) |
Führt einen |
| Invoke(Action[]) |
Führt jede der bereitgestellten Aktionen aus, möglicherweise parallel. |
| Invoke(ParallelOptions, Action[]) |
Führt jede der bereitgestellten Aktionen, möglicherweise parallel, aus, es sei denn, der Vorgang wird vom Benutzer abgebrochen. |
Gilt für:
Threadsicherheit
Alle öffentlichen und geschützten Member von Parallel sind threadsicher und können gleichzeitig aus mehreren Threads verwendet werden.