ConcurrentExclusiveSchedulerPair Osztály
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Olyan feladatütemezőket biztosít, amelyek koordinálják a tevékenységek végrehajtását, ugyanakkor biztosítják, hogy az egyidejű tevékenységek egyidejűleg fussanak, és a kizárólagos tevékenységek soha ne legyenek.
public ref class ConcurrentExclusiveSchedulerPair
public class ConcurrentExclusiveSchedulerPair
type ConcurrentExclusiveSchedulerPair = class
Public Class ConcurrentExclusiveSchedulerPair
- Öröklődés
-
ConcurrentExclusiveSchedulerPair
Példák
Az alábbi példa az osztály használatát ConcurrentExclusiveSchedulerPair mutatja be. Az olvasók az ütemező egyidejű részén futnak. Az író az ütemező kizárólagos részén fut. Ez a példakód a How to: Specify a Task Scheduler in a Dataflow Block article (Feladatütemező megadása adatfolyamblokkoló cikkben ) című nagyobb példa része.
// 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)
Konstruktorok
| Name | Description |
|---|---|
| ConcurrentExclusiveSchedulerPair() |
Inicializálja a ConcurrentExclusiveSchedulerPair osztály új példányát. |
| ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32, Int32) |
Inicializálja az ConcurrentExclusiveSchedulerPair osztály új példányát, amely a megadott ütemezőt célozza meg maximális egyidejűségi szinttel és az egységként feldolgozható ütemezett tevékenységek maximális számával. |
| ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32) |
Inicializálja az ConcurrentExclusiveSchedulerPair osztály új példányát, amely a megadott ütemezőt célozza meg maximális egyidejűségi szinttel. |
| ConcurrentExclusiveSchedulerPair(TaskScheduler) |
Inicializálja az ConcurrentExclusiveSchedulerPair osztály új példányát, amely a megadott ütemezőt célozza. |
Tulajdonságok
| Name | Description |
|---|---|
| Completion |
Task Ez akkor fejeződik be, ha az ütemező befejezte a feldolgozást. |
| ConcurrentScheduler |
TaskScheduler Lekéri azokat a feladatokat, amelyek a pár más tevékenységeivel egyidejűleg futtathatók. |
| ExclusiveScheduler |
Lekéri azokat TaskScheduler a feladatokat, amelyek kizárólag a pár más tevékenységeire vonatkozóan futtatandó tevékenységek ütemezésére használhatók. |
Metódusok
| Name | Description |
|---|---|
| Complete() |
Tájékoztatja az ütemezőpárt, hogy ne fogadjon el több feladatot. |
| Equals(Object) |
Meghatározza, hogy a megadott objektum egyenlő-e az aktuális objektummal. (Öröklődés forrása Object) |
| GetHashCode() |
Ez az alapértelmezett kivonatoló függvény. (Öröklődés forrása Object) |
| GetType() |
Lekéri az Type aktuális példányt. (Öröklődés forrása Object) |
| MemberwiseClone() |
Az aktuális Objectpéldány sekély másolatát hozza létre. (Öröklődés forrása Object) |
| ToString() |
Az aktuális objektumot jelképező sztringet ad vissza. (Öröklődés forrása Object) |