ConcurrentExclusiveSchedulerPair Kelas

Definisi

Menyediakan penjadwal tugas yang berkoordinasi untuk menjalankan tugas sekaligus memastikan bahwa tugas bersamaan dapat berjalan secara bersamaan dan tugas eksklusif tidak pernah dilakukan.

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

Contoh

Contoh berikut menunjukkan penggunaan ConcurrentExclusiveSchedulerPair kelas . Pembaca berjalan pada bagian bersamaan dari penjadwal. Penulis berjalan pada bagian eksklusif penjadwal. Contoh kode ini adalah bagian dari contoh yang lebih besar yang disediakan untuk artikel Cara: Menentukan Penjadwal Tugas dalam Blok Aliran Data .

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

Konstruktor

Nama Deskripsi
ConcurrentExclusiveSchedulerPair()

Menginisialisasi instans baru dari kelas ConcurrentExclusiveSchedulerPair.

ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32, Int32)

Menginisialisasi instans ConcurrentExclusiveSchedulerPair baru kelas yang menargetkan penjadwal yang ditentukan dengan tingkat konkurensi maksimum dan jumlah maksimum tugas terjadwal yang dapat diproses sebagai unit.

ConcurrentExclusiveSchedulerPair(TaskScheduler, Int32)

Menginisialisasi instans ConcurrentExclusiveSchedulerPair baru kelas yang menargetkan penjadwal yang ditentukan dengan tingkat konkurensi maksimum.

ConcurrentExclusiveSchedulerPair(TaskScheduler)

Menginisialisasi instans ConcurrentExclusiveSchedulerPair baru kelas yang menargetkan penjadwal yang ditentukan.

Properti

Nama Deskripsi
Completion

Task Mendapatkan yang akan selesai ketika penjadwal telah menyelesaikan pemrosesan.

ConcurrentScheduler

TaskScheduler Mendapatkan yang dapat digunakan untuk menjadwalkan tugas ke pasangan ini yang dapat berjalan bersamaan dengan tugas lain pada pasangan ini.

ExclusiveScheduler

TaskScheduler Mendapatkan yang dapat digunakan untuk menjadwalkan tugas ke pasangan ini yang harus berjalan secara eksklusif sehubungan dengan tugas lain pada pasangan ini.

Metode

Nama Deskripsi
Complete()

Menginformasikan pasangan penjadwal bahwa pasangan penjadwal tidak boleh menerima tugas lagi.

Equals(Object)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
GetHashCode()

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetType()

Mendapatkan Type instans saat ini.

(Diperoleh dari Object)
MemberwiseClone()

Membuat salinan dangkal dari Objectsaat ini.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Berlaku untuk