すべて静的メソッドです。
メソッド | 機能 |
---|---|
Invoke(params Action[] actions) | |
For(int fromInclusive, int toExclusive, Action<int> body) | |
ForEach<TSource>(IEnumerable<TSource> source, Action<TSource> body) |
public static void Invoke (params Action[] actions);Invoke(Action[]) - Parallel.Invoke メソッド (System.Threading.Tasks) | Microsoft Learn
実行される順序や、並列で実行される保証はありません。またすべての操作が完了するまで、制御を戻しません。
Action action1 = delegate {}; Action action2 = delegate {}; Parallel.Invoke(action1, action2);
くり返しを並列に実行できる、forループを実行できます。
public static System.Threading.Tasks.ParallelLoopResult For ( int fromInclusive, // 開始インデックス int toExclusive, // 終了インデックス Action<int> body // イテレーションごとに1回呼び出されるデリゲート );For(Int32, Int32, Action<Int32>) - Parallel.For メソッド (System.Threading.Tasks) | Microsoft Learn
Parallel.For(0, 5, (a) =>
{
Console.Write(a);
});
// 02341や01342と出力される