vb System.Threading.Tasks.ConcurrentExclusiveSchedulerPair.ExclusiveScheduler类(方法)实例源码

下面列出了vb System.Threading.Tasks.ConcurrentExclusiveSchedulerPair.ExclusiveScheduler 类(方法)源码代码实例,从而了解它的用法。

作者:VB.NET开发    项目:System.Threading.Task   
' 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)


问题


面经


文章

微信
公众号

扫码关注公众号