[このドキュメントはプレビュー版であり、後のリリースで変更されることがあります。 空白のトピックは、プレースホルダーとして挿入されています。]
ソース シーケンスで AsParallel 拡張メソッドを使用して ParallelEnumerableForAll()()() メソッドを使用してクエリの実行、単純な並列 LINQ クエリを作成する例を次に示します。
Dim source = Enumerable.Range(100, 20000)
' Result sequence might be out of order.
Dim parallelQuery = From num In source.AsParallel()
Where num Mod 10 = 0
Select num
' Process result sequence in parallel
parallelQuery.ForAll(Sub(e)
DoSomething(e)
End Sub)
' Or use For Each to merge results first
' as in this example, Where results must
' be serialized sequentially through static Console method.
For Each n In parallelQuery
Console.WriteLine(n)
Next
' You can also use ToArray, ToList, etc
' as with LINQ to Objects.
Dim parallelQuery2 = (From num In source.AsParallel()
Where num Mod 10 = 0
Select num).ToArray()
var source = Enumerable.Range(100, 20000);
// Result sequence might be out of order.
var parallelQuery = from num in source.AsParallel()
where num % 10 == 0
select num;
// Process result sequence in parallel
parallelQuery.ForAll((e) => DoSomething(e));
// Or use foreach to merge results first.
foreach (var n in parallelQuery)
{
Console.WriteLine(n);
}
// You can also use ToArray, ToList, etc
// as with LINQ to Objects.
var parallelQuery2 = (from num in source.AsParallel()
where num % 10 == 0
select num).ToArray();
// Method syntax is also supported
var parallelQuery3 = source.AsParallel().Where(n => n % 10 == 0).Select(n => n);
この例で作成し、結果のシーケンスの順序は重要なときに、並列 LINQ クエリを実行の基本的なパターンを示します(順不同) クエリは、通常、注文のクエリより高速です。 クエリは複数のスレッドで非同期に実行されるタスクに、ソースをパーティションします。 各タスクを完了する順序は、パーティション内の要素を処理する作業の量は、オペレーティング システムの各スレッドのスケジュール方法などの外部要因にもだけでなくによって異なります。 クエリ内の要素の順序を維持する方法については、方法 : PLINQ クエリでの順序付けコントロール を参照してください。
概念