ConcurrentExclusiveSchedulerPair 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 ConcurrentExclusiveSchedulerPair 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| ConcurrentExclusiveSchedulerPair() |
初始化 ConcurrentExclusiveSchedulerPair 類別的新執行個體。 |
| ConcurrentExclusiveSchedulerPair(TaskScheduler) |
初始化一個針對指定排程器的類別新實例 ConcurrentExclusiveSchedulerPair 。 |
| ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32) |
初始化一個新的類別實例 ConcurrentExclusiveSchedulerPair ,目標為指定排程器,並擁有最大並行等級。 |
| ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32, Int32) |
初始化一個新的類別實例 ConcurrentExclusiveSchedulerPair ,針對指定的排程器,並設定最大並行等級及可作為一個單元處理的最大排程任務數量。 |
ConcurrentExclusiveSchedulerPair()
初始化 ConcurrentExclusiveSchedulerPair 類別的新執行個體。
public:
ConcurrentExclusiveSchedulerPair();
public ConcurrentExclusiveSchedulerPair();
Public Sub New ()
範例
以下範例展示了使用 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(TaskScheduler)
初始化一個針對指定排程器的類別新實例 ConcurrentExclusiveSchedulerPair 。
public:
ConcurrentExclusiveSchedulerPair(System::Threading::Tasks::TaskScheduler ^ taskScheduler);
public ConcurrentExclusiveSchedulerPair(System.Threading.Tasks.TaskScheduler taskScheduler);
new System.Threading.Tasks.ConcurrentExclusiveSchedulerPair : System.Threading.Tasks.TaskScheduler -> System.Threading.Tasks.ConcurrentExclusiveSchedulerPair
Public Sub New (taskScheduler As TaskScheduler)
參數
- taskScheduler
- TaskScheduler
這對應執行的目標排程器。
適用於
ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32)
初始化一個新的類別實例 ConcurrentExclusiveSchedulerPair ,目標為指定排程器,並擁有最大並行等級。
public:
ConcurrentExclusiveSchedulerPair(System::Threading::Tasks::TaskScheduler ^ taskScheduler, int maxConcurrencyLevel);
public ConcurrentExclusiveSchedulerPair(System.Threading.Tasks.TaskScheduler taskScheduler, int maxConcurrencyLevel);
new System.Threading.Tasks.ConcurrentExclusiveSchedulerPair : System.Threading.Tasks.TaskScheduler * int -> System.Threading.Tasks.ConcurrentExclusiveSchedulerPair
Public Sub New (taskScheduler As TaskScheduler, maxConcurrencyLevel As Integer)
參數
- taskScheduler
- TaskScheduler
這對應執行的目標排程器。
- maxConcurrencyLevel
- Int32
同時執行的最大任務數量。
適用於
ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32, Int32)
初始化一個新的類別實例 ConcurrentExclusiveSchedulerPair ,針對指定的排程器,並設定最大並行等級及可作為一個單元處理的最大排程任務數量。
public:
ConcurrentExclusiveSchedulerPair(System::Threading::Tasks::TaskScheduler ^ taskScheduler, int maxConcurrencyLevel, int maxItemsPerTask);
public ConcurrentExclusiveSchedulerPair(System.Threading.Tasks.TaskScheduler taskScheduler, int maxConcurrencyLevel, int maxItemsPerTask);
new System.Threading.Tasks.ConcurrentExclusiveSchedulerPair : System.Threading.Tasks.TaskScheduler * int * int -> System.Threading.Tasks.ConcurrentExclusiveSchedulerPair
Public Sub New (taskScheduler As TaskScheduler, maxConcurrencyLevel As Integer, maxItemsPerTask As Integer)
參數
- taskScheduler
- TaskScheduler
這對應執行的目標排程器。
- maxConcurrencyLevel
- Int32
同時執行的最大任務數量。
- maxItemsPerTask
- Int32
每個底層排程任務中,配對可處理的最大任務數量。