ConcurrentExclusiveSchedulerPair 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 ConcurrentExclusiveSchedulerPair 类的新实例。
重载
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
要处理的被成对用于每一个基础计划任务的最大任务数。