ConcurrentExclusiveSchedulerPair Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Fornisce utilità di pianificazione che coordinano l'esecuzione di attività, assicurandosi che le attività simultanee possano essere eseguite simultaneamente e le attività esclusive non vengano mai eseguite.
public ref class ConcurrentExclusiveSchedulerPair
public class ConcurrentExclusiveSchedulerPair
type ConcurrentExclusiveSchedulerPair = class
Public Class ConcurrentExclusiveSchedulerPair
- Ereditarietà
-
ConcurrentExclusiveSchedulerPair
Esempio
Nell'esempio seguente viene illustrato l'uso della ConcurrentExclusiveSchedulerPair classe . I lettori vengono eseguiti nella parte simultanea dell'utilità di pianificazione. Il writer viene eseguito nella parte esclusiva dell'utilità di pianificazione. Questo esempio di codice fa parte di un esempio più ampio fornito per l'articolo Procedura: Specificare un'utilità di pianificazione in un blocco di flussi di dati .
// 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)
Costruttori
| Nome | Descrizione |
|---|---|
| ConcurrentExclusiveSchedulerPair() |
Inizializza una nuova istanza della classe ConcurrentExclusiveSchedulerPair. |
| ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32, Int32) |
Inizializza una nuova istanza della ConcurrentExclusiveSchedulerPair classe destinata all'utilità di pianificazione specificata con un livello di concorrenza massimo e un numero massimo di attività pianificate che possono essere elaborate come unità. |
| ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32) |
Inizializza una nuova istanza della ConcurrentExclusiveSchedulerPair classe destinata all'utilità di pianificazione specificata con un livello di concorrenza massimo. |
| ConcurrentExclusiveSchedulerPair(TaskScheduler) |
Inizializza una nuova istanza della ConcurrentExclusiveSchedulerPair classe destinata all'utilità di pianificazione specificata. |
Proprietà
| Nome | Descrizione |
|---|---|
| Completion |
Ottiene un oggetto Task che verrà completato al termine dell'elaborazione dell'utilità di pianificazione. |
| ConcurrentScheduler |
Ottiene un oggetto TaskScheduler che può essere utilizzato per pianificare le attività di questa coppia che possono essere eseguite simultaneamente con altre attività in questa coppia. |
| ExclusiveScheduler |
Ottiene un oggetto TaskScheduler che può essere utilizzato per pianificare le attività di questa coppia che devono essere eseguite esclusivamente in relazione ad altre attività in questa coppia. |
Metodi
| Nome | Descrizione |
|---|---|
| Complete() |
Informa la coppia dell'utilità di pianificazione che non deve accettare altre attività. |
| Equals(Object) |
Determina se l'oggetto specificato è uguale all'oggetto corrente. (Ereditato da Object) |
| GetHashCode() |
Funge da funzione hash predefinita. (Ereditato da Object) |
| GetType() |
Ottiene il Type dell'istanza corrente. (Ereditato da Object) |
| MemberwiseClone() |
Crea una copia superficiale del Objectcorrente. (Ereditato da Object) |
| ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |