ConcurrentExclusiveSchedulerPair Constructors

Definition

Initializes a new instance of the ConcurrentExclusiveSchedulerPair class.

Overloads

ConcurrentExclusiveSchedulerPair()

Initializes a new instance of the ConcurrentExclusiveSchedulerPair class.

ConcurrentExclusiveSchedulerPair(TaskScheduler)

Initializes a new instance of the ConcurrentExclusiveSchedulerPair class that targets the specified scheduler.

ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32)

Initializes a new instance of the ConcurrentExclusiveSchedulerPair class that targets the specified scheduler with a maximum concurrency level.

ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32, Int32)

Initializes a new instance of the ConcurrentExclusiveSchedulerPair class that targets the specified scheduler with a maximum concurrency level and a maximum number of scheduled tasks that may be processed as a unit.

ConcurrentExclusiveSchedulerPair()

Source:
ConcurrentExclusiveSchedulerPair.cs
Source:
ConcurrentExclusiveSchedulerPair.cs
Source:
ConcurrentExclusiveSchedulerPair.cs

Initializes a new instance of the ConcurrentExclusiveSchedulerPair class.

C#
public ConcurrentExclusiveSchedulerPair();

Examples

The following example shows the use of the ConcurrentExclusiveSchedulerPair constructor to create a new ConcurrentExclusiveSchedulerPair object. This code example is part of a larger example provided for the How to: Specify a Task Scheduler in a Dataflow Block article.

C#
// 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);

Applies to

.NET 10 a ďalšie verzie
Produkt Verzie
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

ConcurrentExclusiveSchedulerPair(TaskScheduler)

Source:
ConcurrentExclusiveSchedulerPair.cs
Source:
ConcurrentExclusiveSchedulerPair.cs
Source:
ConcurrentExclusiveSchedulerPair.cs

Initializes a new instance of the ConcurrentExclusiveSchedulerPair class that targets the specified scheduler.

C#
public ConcurrentExclusiveSchedulerPair(System.Threading.Tasks.TaskScheduler taskScheduler);

Parameters

taskScheduler
TaskScheduler

The target scheduler on which this pair should execute.

Applies to

.NET 10 a ďalšie verzie
Produkt Verzie
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32)

Source:
ConcurrentExclusiveSchedulerPair.cs
Source:
ConcurrentExclusiveSchedulerPair.cs
Source:
ConcurrentExclusiveSchedulerPair.cs

Initializes a new instance of the ConcurrentExclusiveSchedulerPair class that targets the specified scheduler with a maximum concurrency level.

C#
public ConcurrentExclusiveSchedulerPair(System.Threading.Tasks.TaskScheduler taskScheduler, int maxConcurrencyLevel);

Parameters

taskScheduler
TaskScheduler

The target scheduler on which this pair should execute.

maxConcurrencyLevel
Int32

The maximum number of tasks to run concurrently.

Applies to

.NET 10 a ďalšie verzie
Produkt Verzie
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32, Int32)

Source:
ConcurrentExclusiveSchedulerPair.cs
Source:
ConcurrentExclusiveSchedulerPair.cs
Source:
ConcurrentExclusiveSchedulerPair.cs

Initializes a new instance of the ConcurrentExclusiveSchedulerPair class that targets the specified scheduler with a maximum concurrency level and a maximum number of scheduled tasks that may be processed as a unit.

C#
public ConcurrentExclusiveSchedulerPair(System.Threading.Tasks.TaskScheduler taskScheduler, int maxConcurrencyLevel, int maxItemsPerTask);

Parameters

taskScheduler
TaskScheduler

The target scheduler on which this pair should execute.

maxConcurrencyLevel
Int32

The maximum number of tasks to run concurrently.

maxItemsPerTask
Int32

The maximum number of tasks to process for each underlying scheduled task used by the pair.

Applies to

.NET 10 a ďalšie verzie
Produkt Verzie
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0