ConcurrentExclusiveSchedulerPair Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Tillhandahåller uppgiftsschemaläggare som samordnar för att köra aktiviteter samtidigt som samtidiga aktiviteter kan köras samtidigt och uteslutande uppgifter aldrig gör det.
public ref class ConcurrentExclusiveSchedulerPair
public class ConcurrentExclusiveSchedulerPair
type ConcurrentExclusiveSchedulerPair = class
Public Class ConcurrentExclusiveSchedulerPair
- Arv
-
ConcurrentExclusiveSchedulerPair
Exempel
I följande exempel visas hur klassen används ConcurrentExclusiveSchedulerPair . Läsare körs på den samtidiga delen av schemaläggaren. Författaren körs på den exklusiva delen av schemaläggaren. Det här kodexemplet är en del av ett större exempel för artikeln Så här anger du en schemaläggare i ett dataflödesblock .
// 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)
Konstruktorer
| Name | Description |
|---|---|
| ConcurrentExclusiveSchedulerPair() |
Initierar en ny instans av ConcurrentExclusiveSchedulerPair klassen. |
| ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32, Int32) |
Initierar en ny instans av ConcurrentExclusiveSchedulerPair klassen som riktar sig mot den angivna schemaläggaren med en maximal samtidighetsnivå och ett maximalt antal schemalagda aktiviteter som kan bearbetas som en enhet. |
| ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32) |
Initierar en ny instans av ConcurrentExclusiveSchedulerPair klassen som riktar sig mot den angivna schemaläggaren med en högsta samtidighetsnivå. |
| ConcurrentExclusiveSchedulerPair(TaskScheduler) |
Initierar en ny instans av ConcurrentExclusiveSchedulerPair klassen som riktar sig till den angivna schemaläggaren. |
Egenskaper
| Name | Description |
|---|---|
| Completion |
Hämtar en Task som slutförs när schemaläggaren har slutfört bearbetningen. |
| ConcurrentScheduler |
Hämtar en TaskScheduler som kan användas för att schemalägga aktiviteter till det här paret som kan köras samtidigt med andra aktiviteter i det här paret. |
| ExclusiveScheduler |
Hämtar en TaskScheduler som kan användas för att schemalägga aktiviteter till det här paret som måste köras uteslutande med avseende på andra uppgifter i det här paret. |
Metoder
| Name | Description |
|---|---|
| Complete() |
Informerar schemaläggarparet om att det inte bör acceptera fler uppgifter. |
| Equals(Object) |
Avgör om det angivna objektet är lika med det aktuella objektet. (Ärvd från Object) |
| GetHashCode() |
Fungerar som standard-hash-funktion. (Ärvd från Object) |
| GetType() |
Hämtar den aktuella instansen Type . (Ärvd från Object) |
| MemberwiseClone() |
Skapar en ytlig kopia av den aktuella Object. (Ärvd från Object) |
| ToString() |
Returnerar en sträng som representerar det aktuella objektet. (Ärvd från Object) |