翻訳への提案を行います
 
他のユーザーによる提案:

progress indicator
他の提案はありません。
 印刷用ページ       送信     
クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
並列プログラミング
並列 LINQ (PLINQ)
 方法: 単純な PLINQ クエリを作成して実行する
すべて縮小/すべて展開 すべて縮小
コンテンツの表示:   英語と日本語を並べて表示コンテンツの表示: 英語と日本語を並べて表示
このページは、ベータ版用に機械翻訳されたものです。翻訳者による翻訳は、製品の正規版で提供される予定です。詳細についてはよくある質問 を参照してください。またぜひこちら からアンケートにもご協力ください。
How to: Create and Execute a Simple PLINQ Query

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

The following example shows how to create a simple Parallel LINQ query by using the AsParallel extension method on the source sequence, and executing the query by using the ParallelEnumerableForAll()()() method.

Visual Basic
                        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)
                                 EndSub)

            ' Or use For Each to merge results first            ' as in this example, Where results must            ' be serialized sequentially through static Console method.ForEach 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()


C#
                        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 supportedvar parallelQuery3 = source.AsParallel().Where(n => n % 10 == 0).Select(n => n);

This example demonstrates the basic pattern for creating and executing any Parallel LINQ query when the ordering of the result sequence is not important; unordered queries are generally faster than ordered queries. The query partitions the source into tasks that are executed asynchronously on multiple threads. The order in which each task completes depends not only on the amount of work involved to process the elements in the partition, but also on external factors such as how the operating system schedules each thread. For more information about how to preserve the ordering of elements in a query, see How to: Control Ordering in a PLINQ Query.

.NET Framework 4
方法: 単純な PLINQ クエリを作成して実行する

[このドキュメントはプレビュー版であり、後のリリースで変更されることがあります。 空白のトピックは、プレースホルダーとして挿入されています。]

ソース シーケンスで AsParallel 拡張メソッドを使用して ParallelEnumerableForAll()()() メソッドを使用してクエリの実行、単純な並列 LINQ クエリを作成する例を次に示します。

Visual Basic
                        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)
                                 EndSub)

            ' Or use For Each to merge results first            ' as in this example, Where results must            ' be serialized sequentially through static Console method.ForEach 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()


C#
                        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 supportedvar parallelQuery3 = source.AsParallel().Where(n => n % 10 == 0).Select(n => n);

この例で作成し、結果のシーケンスの順序は重要なときに、並列 LINQ クエリを実行の基本的なパターンを示します(順不同) クエリは、通常、注文のクエリより高速です。 クエリは複数のスレッドで非同期に実行されるタスクに、ソースをパーティションします。 各タスクを完了する順序は、パーティション内の要素を処理する作業の量は、オペレーティング システムの各スレッドのスケジュール方法などの外部要因にもだけでなくによって異なります。 クエリ内の要素の順序を維持する方法については、方法 : PLINQ クエリでの順序付けコントロール を参照してください。

© 2009 Microsoft Corporation. All rights reserved. 使用条件 | 商標 | プライバシー
Page view tracker