Compartir a través de


ConcurrentExclusiveSchedulerPair Constructores

Definición

Inicializa una nueva instancia de la clase ConcurrentExclusiveSchedulerPair.

Sobrecargas

ConcurrentExclusiveSchedulerPair()

Inicializa una nueva instancia de la clase ConcurrentExclusiveSchedulerPair.

ConcurrentExclusiveSchedulerPair(TaskScheduler)

Inicializa una nueva instancia de la clase ConcurrentExclusiveSchedulerPair que se destina al programador especificado.

ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32)

Inicializa una nueva instancia de la clase ConcurrentExclusiveSchedulerPair destinada al programador especificado con un nivel de simultaneidad máximo.

ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32, Int32)

Inicializa una nueva instancia de la clase ConcurrentExclusiveSchedulerPair destinada al programador especificado con un nivel de simultaneidad máximo y un número de tareas programadas máximo que se pueden procesar como una unidad.

ConcurrentExclusiveSchedulerPair()

Inicializa una nueva instancia de la clase ConcurrentExclusiveSchedulerPair.

public:
 ConcurrentExclusiveSchedulerPair();
public ConcurrentExclusiveSchedulerPair ();
Public Sub New ()

Ejemplos

En el ejemplo siguiente se muestra el uso del ConcurrentExclusiveSchedulerPair constructor para crear un nuevo ConcurrentExclusiveSchedulerPair objeto. Este ejemplo de código forma parte de un ejemplo más grande proporcionado para el artículo Cómo: Especificar un programador de tareas en un bloque de flujo de datos .

// 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)

Se aplica a

ConcurrentExclusiveSchedulerPair(TaskScheduler)

Inicializa una nueva instancia de la clase ConcurrentExclusiveSchedulerPair que se destina al programador especificado.

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)

Parámetros

taskScheduler
TaskScheduler

El programador de destino en el que se debe ejecutar este par.

Se aplica a

ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32)

Inicializa una nueva instancia de la clase ConcurrentExclusiveSchedulerPair destinada al programador especificado con un nivel de simultaneidad máximo.

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)

Parámetros

taskScheduler
TaskScheduler

El programador de destino en el que se debe ejecutar este par.

maxConcurrencyLevel
Int32

Número máximo de tareas que se van a ejecutar simultáneamente.

Se aplica a

ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32, Int32)

Inicializa una nueva instancia de la clase ConcurrentExclusiveSchedulerPair destinada al programador especificado con un nivel de simultaneidad máximo y un número de tareas programadas máximo que se pueden procesar como una unidad.

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)

Parámetros

taskScheduler
TaskScheduler

El programador de destino en el que se debe ejecutar este par.

maxConcurrencyLevel
Int32

Número máximo de tareas que se van a ejecutar simultáneamente.

maxItemsPerTask
Int32

Número máximo de tareas para procesar para cada tarea programada subyacente usada por el par.

Se aplica a