ConcurrentExclusiveSchedulerPair Classe
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Fournit des planificateurs de tâches qui coordonnent l’exécution des tâches tout en garantissant que les tâches simultanées peuvent s’exécuter simultanément et les tâches exclusives ne le font jamais.
public ref class ConcurrentExclusiveSchedulerPair
public class ConcurrentExclusiveSchedulerPair
type ConcurrentExclusiveSchedulerPair = class
Public Class ConcurrentExclusiveSchedulerPair
- Héritage
-
ConcurrentExclusiveSchedulerPair
Exemples
L’exemple suivant montre l’utilisation de la ConcurrentExclusiveSchedulerPair classe. Les lecteurs s’exécutent sur la partie simultanée du planificateur. L’enregistreur s’exécute dans la partie exclusive du planificateur. Cet exemple de code fait partie d’un exemple plus large fourni pour l’article How to : Specify a Task Scheduler in a Dataflow Block article.
// 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)
Constructeurs
| Nom | Description |
|---|---|
| ConcurrentExclusiveSchedulerPair() |
Initialise une nouvelle instance de la classe ConcurrentExclusiveSchedulerPair. |
| ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32, Int32) |
Initialise une nouvelle instance de la ConcurrentExclusiveSchedulerPair classe qui cible le planificateur spécifié avec un niveau d’accès concurrentiel maximal et un nombre maximal de tâches planifiées qui peuvent être traitées en tant qu’unité. |
| ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32) |
Initialise une nouvelle instance de la ConcurrentExclusiveSchedulerPair classe qui cible le planificateur spécifié avec un niveau d’accès concurrentiel maximal. |
| ConcurrentExclusiveSchedulerPair(TaskScheduler) |
Initialise une nouvelle instance de la ConcurrentExclusiveSchedulerPair classe qui cible le planificateur spécifié. |
Propriétés
| Nom | Description |
|---|---|
| Completion |
Obtient une Task opération qui se termine lorsque le planificateur a terminé le traitement. |
| ConcurrentScheduler |
Obtient un TaskScheduler élément qui peut être utilisé pour planifier des tâches sur cette paire qui peuvent s’exécuter simultanément avec d’autres tâches sur cette paire. |
| ExclusiveScheduler |
Obtient un TaskScheduler élément qui peut être utilisé pour planifier des tâches sur cette paire qui doivent s’exécuter exclusivement en ce qui concerne d’autres tâches sur cette paire. |
Méthodes
| Nom | Description |
|---|---|
| Complete() |
Informe la paire planificateur qu’elle ne doit pas accepter plus de tâches. |
| Equals(Object) |
Détermine si l’objet spécifié est égal à l’objet actuel. (Hérité de Object) |
| GetHashCode() |
Sert de fonction de hachage par défaut. (Hérité de Object) |
| GetType() |
Obtient la Type de l’instance actuelle. (Hérité de Object) |
| MemberwiseClone() |
Crée une copie superficielle du Objectactuel. (Hérité de Object) |
| ToString() |
Retourne une chaîne qui représente l’objet actuel. (Hérité de Object) |