ConcurrentExclusiveSchedulerPair Klasa

Definicja

Udostępnia harmonogramy zadań, które koordynują wykonywanie zadań przy jednoczesnym zapewnieniu, że współbieżne zadania mogą być uruchamiane współbieżnie i nigdy nie są wykonywane wyłącznie zadania.

public ref class ConcurrentExclusiveSchedulerPair
public class ConcurrentExclusiveSchedulerPair
type ConcurrentExclusiveSchedulerPair = class
Public Class ConcurrentExclusiveSchedulerPair
Dziedziczenie
ConcurrentExclusiveSchedulerPair

Przykłady

W poniższym przykładzie pokazano użycie ConcurrentExclusiveSchedulerPair klasy. Czytelnicy są uruchamiani w równoczesnej części harmonogramu. Pisarz działa w ekskluzywnej części harmonogramu. Ten przykład kodu jest częścią większego przykładu podanego w artykule How to: Specify a Task Scheduler in a Dataflow Block (Jak określić harmonogram zadań w bloku przepływu danych ).

// 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)

Konstruktory

ConcurrentExclusiveSchedulerPair()

Inicjuje nowe wystąpienie klasy ConcurrentExclusiveSchedulerPair.

ConcurrentExclusiveSchedulerPair(TaskScheduler)

Inicjuje ConcurrentExclusiveSchedulerPair nowe wystąpienie klasy, która jest przeznaczona dla określonego harmonogramu.

ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32)

Inicjuje nowe wystąpienie klasy, która jest przeznaczona dla określonego ConcurrentExclusiveSchedulerPair harmonogramu z maksymalnym poziomem współbieżności.

ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32, Int32)

Inicjuje nowe wystąpienie ConcurrentExclusiveSchedulerPair klasy, które jest przeznaczone dla określonego harmonogramu z maksymalnym poziomem współbieżności i maksymalną liczbą zaplanowanych zadań, które mogą być przetwarzane jako jednostka.

Właściwości

Completion

Pobiera element Task , który zostanie ukończony po zakończeniu przetwarzania przez harmonogram.

ConcurrentScheduler

Pobiera element TaskScheduler , który może służyć do planowania zadań do tej pary, które mogą być uruchamiane współbieżnie z innymi zadaniami w tej parze.

ExclusiveScheduler

Pobiera element TaskScheduler , który może służyć do planowania zadań do tej pary, które muszą być uruchamiane wyłącznie w odniesieniu do innych zadań w tej parze.

Metody

Complete()

Informuje parę harmonogramu, że nie powinna akceptować żadnych dodatkowych zadań.

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy