ConcurrentExclusiveSchedulerPair Clase
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Proporciona programadores de tareas que se coordinan para ejecutar tareas a la vez que garantizan que las tareas simultáneas se puedan ejecutar simultáneamente y las tareas exclusivas nunca lo hagan.
public ref class ConcurrentExclusiveSchedulerPair
public class ConcurrentExclusiveSchedulerPair
type ConcurrentExclusiveSchedulerPair = class
Public Class ConcurrentExclusiveSchedulerPair
- Herencia
-
ConcurrentExclusiveSchedulerPair
Ejemplos
En el ejemplo siguiente se muestra el uso de la ConcurrentExclusiveSchedulerPair clase . Los lectores se ejecutan en la parte simultánea del programador. El escritor se ejecuta en la parte exclusiva del programador. Este ejemplo de código forma parte de un ejemplo más grande proporcionado para el artículo How to: Specify a Task Scheduler in a Dataflow Block (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)
Constructores
| Nombre | Description |
|---|---|
| ConcurrentExclusiveSchedulerPair() |
Inicializa una nueva instancia de la clase ConcurrentExclusiveSchedulerPair. |
| ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32, Int32) |
Inicializa una nueva instancia de la ConcurrentExclusiveSchedulerPair clase que tiene como destino el programador especificado con un nivel de simultaneidad máximo y un número máximo de tareas programadas que se pueden procesar como una unidad. |
| ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32) |
Inicializa una nueva instancia de la ConcurrentExclusiveSchedulerPair clase que tiene como destino el programador especificado con un nivel máximo de simultaneidad. |
| ConcurrentExclusiveSchedulerPair(TaskScheduler) |
Inicializa una nueva instancia de la ConcurrentExclusiveSchedulerPair clase que tiene como destino el programador especificado. |
Propiedades
| Nombre | Description |
|---|---|
| Completion |
Obtiene un Task objeto que se completará cuando el programador haya completado el procesamiento. |
| ConcurrentScheduler |
Obtiene un TaskScheduler objeto que se puede usar para programar tareas en este par que se pueden ejecutar simultáneamente con otras tareas de este par. |
| ExclusiveScheduler |
Obtiene un TaskScheduler objeto que se puede usar para programar tareas en este par que se deben ejecutar exclusivamente con respecto a otras tareas de este par. |
Métodos
| Nombre | Description |
|---|---|
| Complete() |
Informa al par del programador de que no debe aceptar más tareas. |
| Equals(Object) |
Determina si el objeto especificado es igual al objeto actual. (Heredado de Object) |
| GetHashCode() |
Actúa como función hash predeterminada. (Heredado de Object) |
| GetType() |
Obtiene el Type de la instancia actual. (Heredado de Object) |
| MemberwiseClone() |
Crea una copia superficial del Objectactual. (Heredado de Object) |
| ToString() |
Devuelve una cadena que representa el objeto actual. (Heredado de Object) |