ConcurrentExclusiveSchedulerPair クラス

定義

同時実行タスクが同時に実行され、排他タスクが実行されないようにしながら、タスクを実行するように調整するタスク スケジューラを提供します。

public ref class ConcurrentExclusiveSchedulerPair
public class ConcurrentExclusiveSchedulerPair
type ConcurrentExclusiveSchedulerPair = class
Public Class ConcurrentExclusiveSchedulerPair
継承
ConcurrentExclusiveSchedulerPair

次の例は、 ConcurrentExclusiveSchedulerPair クラスの使用方法を示しています。 リーダーは、スケジューラの同時実行部分で実行されます。 ライターは、スケジューラの排他部分で実行されます。 このコード例は、 データフロー ブロックでタスク スケジューラを指定する方法に関する記事で提供 される、より大きな例の一部です。

// Create a ConcurrentExclusiveSchedulerPair object.
// Readers will run on the concurrent part of the scheduler pair.
// The writer will run on the exclusive part of the scheduler pair.
var taskSchedulerPair = new ConcurrentExclusiveSchedulerPair();

// Create an ActionBlock<int> object for each reader CheckBox object.
// Each ActionBlock<int> object represents an action that can read 
// from a resource in parallel to other readers.
// Specifying the concurrent part of the scheduler pair enables the 
// reader to run in parallel to other actions that are managed by 
// that scheduler.
var readerActions =
   from checkBox in new CheckBox[] { checkBox1, checkBox2, checkBox3 }
   select new ActionBlock<int>(milliseconds =>
   {
       // Toggle the check box to the checked state.
       toggleCheckBox.Post(checkBox);

       // Perform the read action. For demonstration, suspend the current
       // thread to simulate a lengthy read operation.
       Thread.Sleep(milliseconds);

       // Toggle the check box to the unchecked state.
       toggleCheckBox.Post(checkBox);
   },
   new ExecutionDataflowBlockOptions
   {
       TaskScheduler = taskSchedulerPair.ConcurrentScheduler
   });

// Create an ActionBlock<int> object for the writer CheckBox object.
// This ActionBlock<int> object represents an action that writes to 
// a resource, but cannot run in parallel to readers.
// Specifying the exclusive part of the scheduler pair enables the 
// writer to run in exclusively with respect to other actions that are 
// managed by the scheduler pair.
var writerAction = new ActionBlock<int>(milliseconds =>
{
    // Toggle the check box to the checked state.
    toggleCheckBox.Post(checkBox4);

    // Perform the write action. For demonstration, suspend the current
    // thread to simulate a lengthy write operation.
    Thread.Sleep(milliseconds);

    // Toggle the check box to the unchecked state.
    toggleCheckBox.Post(checkBox4);
},
new ExecutionDataflowBlockOptions
{
    TaskScheduler = taskSchedulerPair.ExclusiveScheduler
});

// Link the broadcaster to each reader and writer block.
// The BroadcastBlock<T> class propagates values that it 
// receives to all connected targets.
foreach (var readerAction in readerActions)
{
    broadcaster.LinkTo(readerAction);
}
broadcaster.LinkTo(writerAction);
' Create a ConcurrentExclusiveSchedulerPair object.
' Readers will run on the concurrent part of the scheduler pair.
' The writer will run on the exclusive part of the scheduler pair.
Dim taskSchedulerPair = New ConcurrentExclusiveSchedulerPair()

' Create an ActionBlock<int> object for each reader CheckBox object.
' Each ActionBlock<int> object represents an action that can read 
' from a resource in parallel to other readers.
' Specifying the concurrent part of the scheduler pair enables the 
' reader to run in parallel to other actions that are managed by 
' that scheduler.
Dim readerActions = From checkBox In New CheckBox() {checkBox1, checkBox2, checkBox3}
                    Select New ActionBlock(Of Integer)(Sub(milliseconds)
                                                           ' Toggle the check box to the checked state.
                                                           ' Perform the read action. For demonstration, suspend the current
                                                           ' thread to simulate a lengthy read operation.
                                                           ' Toggle the check box to the unchecked state.
                                                           toggleCheckBox.Post(checkBox)
                                                           Thread.Sleep(milliseconds)
                                                           toggleCheckBox.Post(checkBox)
                                                       End Sub, New ExecutionDataflowBlockOptions With {.TaskScheduler = taskSchedulerPair.ConcurrentScheduler})

' Create an ActionBlock<int> object for the writer CheckBox object.
' This ActionBlock<int> object represents an action that writes to 
' a resource, but cannot run in parallel to readers.
' Specifying the exclusive part of the scheduler pair enables the 
' writer to run in exclusively with respect to other actions that are 
' managed by the scheduler pair.
Dim writerAction = New ActionBlock(Of Integer)(Sub(milliseconds)
                                                   ' Toggle the check box to the checked state.
                                                   ' Perform the write action. For demonstration, suspend the current
                                                   ' thread to simulate a lengthy write operation.
                                                   ' Toggle the check box to the unchecked state.
                                                   toggleCheckBox.Post(checkBox4)
                                                   Thread.Sleep(milliseconds)
                                                   toggleCheckBox.Post(checkBox4)
                                               End Sub, New ExecutionDataflowBlockOptions With {.TaskScheduler = taskSchedulerPair.ExclusiveScheduler})

' Link the broadcaster to each reader and writer block.
' The BroadcastBlock<T> class propagates values that it 
' receives to all connected targets.
For Each readerAction In readerActions
    broadcaster.LinkTo(readerAction)
Next readerAction
broadcaster.LinkTo(writerAction)

コンストラクター

名前 説明
ConcurrentExclusiveSchedulerPair()

ConcurrentExclusiveSchedulerPair クラスの新しいインスタンスを初期化します。

ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32, Int32)

指定したスケジューラを対象とする ConcurrentExclusiveSchedulerPair クラスの新しいインスタンスを、最大コンカレンシー レベルと、1 つの単位として処理できるスケジュールされたタスクの最大数で初期化します。

ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32)

指定したスケジューラを対象とする ConcurrentExclusiveSchedulerPair クラスの新しいインスタンスを、最大コンカレンシー レベルで初期化します。

ConcurrentExclusiveSchedulerPair(TaskScheduler)

指定したスケジューラを対象とする ConcurrentExclusiveSchedulerPair クラスの新しいインスタンスを初期化します。

プロパティ

名前 説明
Completion

スケジューラの処理が完了したときに完了する Task を取得します。

ConcurrentScheduler

このペアの他のタスクと同時に実行できるタスクをこのペアにスケジュールするために使用できる TaskScheduler を取得します。

ExclusiveScheduler

このペアの他のタスクに関して排他的に実行する必要があるタスクをこのペアにスケジュールするために使用できる TaskScheduler を取得します。

メソッド

名前 説明
Complete()

それ以上のタスクを受け入れないことをスケジューラペアに通知します。

Equals(Object)

指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象