ConcurrentExclusiveSchedulerPair ConcurrentExclusiveSchedulerPair ConcurrentExclusiveSchedulerPair ConcurrentExclusiveSchedulerPair Class

Definición

Proporciona programadores de tareas que se coordinan para ejecutar las tareas a la vez que garantizan que las tareas simultáneas puedan ejecutarse en paralelo y las tareas excluyentes nunca lo hagan así.Provides task schedulers that coordinate to execute tasks while ensuring that concurrent tasks may run concurrently and exclusive tasks never do.

public ref class ConcurrentExclusiveSchedulerPair
public class ConcurrentExclusiveSchedulerPair
type ConcurrentExclusiveSchedulerPair = class
Public Class ConcurrentExclusiveSchedulerPair
Herencia
ConcurrentExclusiveSchedulerPairConcurrentExclusiveSchedulerPairConcurrentExclusiveSchedulerPairConcurrentExclusiveSchedulerPair

Ejemplos

En el ejemplo siguiente se muestra el uso ConcurrentExclusiveSchedulerPair de la clase.The following example shows the use of the ConcurrentExclusiveSchedulerPair class. Los lectores se ejecutan en la parte simultánea del programador.Readers run on the concurrent part of the scheduler. El escritor se ejecuta en la parte exclusiva del programador.The writer runs on the exclusive part of the scheduler. Este ejemplo de código forma parte de un ejemplo más grande proporcionado para el procedimiento: Especifique un programador de tareas en un tema de bloque de flujo de entrada.This code example is part of a larger example provided for the How to: Specify a Task Scheduler in a Dataflow Block topic.

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

Constructores

ConcurrentExclusiveSchedulerPair() ConcurrentExclusiveSchedulerPair() ConcurrentExclusiveSchedulerPair() ConcurrentExclusiveSchedulerPair()

Inicializa una nueva instancia de la clase ConcurrentExclusiveSchedulerPair.Initializes a new instance of the ConcurrentExclusiveSchedulerPair class.

ConcurrentExclusiveSchedulerPair(TaskScheduler) ConcurrentExclusiveSchedulerPair(TaskScheduler) ConcurrentExclusiveSchedulerPair(TaskScheduler) ConcurrentExclusiveSchedulerPair(TaskScheduler)

Inicializa una nueva instancia de la clase ConcurrentExclusiveSchedulerPair que se destina al programador especificado.Initializes a new instance of the ConcurrentExclusiveSchedulerPair class that targets the specified scheduler.

ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32) ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32) ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32) ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32)

Inicializa una nueva instancia de la clase ConcurrentExclusiveSchedulerPair destinada al programador especificado con un nivel de simultaneidad máximo.Initializes a new instance of the ConcurrentExclusiveSchedulerPair class that targets the specified scheduler with a maximum concurrency level.

ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32, Int32) ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32, Int32) ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32, Int32) 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.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.

Propiedades

Completion Completion Completion Completion

Obtiene un objeto Task que se completará cuando el programador haya completado el procesamiento.Gets a Task that will complete when the scheduler has completed processing.

ConcurrentScheduler ConcurrentScheduler ConcurrentScheduler ConcurrentScheduler

Obtiene un objeto TaskScheduler que se puede utilizar para programar tareas en este par que puede ejecutarse simultáneamente con otras tareas de este par.Gets a TaskScheduler that can be used to schedule tasks to this pair that may run concurrently with other tasks on this pair.

ExclusiveScheduler ExclusiveScheduler ExclusiveScheduler ExclusiveScheduler

Obtiene un objeto TaskScheduler que se puede utilizarse para programar tareas en este par que deben ejecutarse exclusivamente con respecto a otras tareas de este par.Gets a TaskScheduler that can be used to schedule tasks to this pair that must run exclusively with regards to other tasks on this pair.

Métodos

Complete() Complete() Complete() Complete()

Informa al par de programadores que no debe aceptar más tareas.Informs the scheduler pair that it should not accept any more tasks.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina si el objeto especificado es igual al objeto actual.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Sirve como la función hash predeterminada.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficial del objeto Object actual.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Devuelve una cadena que representa el objeto actual.Returns a string that represents the current object.

(Inherited from Object)

Se aplica a