本文整理汇总了VB.NET中System.Threading.Thread.Priority属性的典型用法代码示例。如果您正苦于以下问题:VB.NET Thread.Priority属性的具体用法?VB.NET Thread.Priority怎么用?VB.NET Thread.Priority使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Threading.Thread
的用法示例。
在下文中一共展示了Thread.Priority属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
' 导入命名空间
Imports System.Threading
Imports Timers = System.Timers
Public Module Example
Dim t As Timers.Timer
Private priorityTest As New PriorityTest()
Public Sub Main()
Dim thread1 As New Thread(AddressOf priorityTest.ThreadMethod)
thread1.Name = "ThreadOne"
Dim thread2 As New Thread(AddressOf priorityTest.ThreadMethod)
thread2.Name = "ThreadTwo"
thread2.Priority = ThreadPriority.BelowNormal
Dim thread3 As New Thread(AddressOf priorityTest.ThreadMethod)
thread3.Name = "ThreadThree"
thread3.Priority = ThreadPriority.AboveNormal
thread1.Start()
thread2.Start()
thread3.Start()
' Allow threads to execute for about 10 seconds.
t = New Timers.Timer()
t.AutoReset = False
t.Interval = 10000
AddHandler t.Elapsed, AddressOf Elapsed
t.Start()
End Sub
Private Sub Elapsed(sender As Object, e As Timers.ElapsedEventArgs)
priorityTest.LoopSwitch = False
End Sub
End Module
Public Class PriorityTest
Private Shared loopSwitchValue As Boolean
<ThreadStatic> Shared threadCount As Long
Sub New()
loopSwitchValue = True
End Sub
WriteOnly Property LoopSwitch As Boolean
Set
loopSwitchValue = Value
End Set
End Property
Sub ThreadMethod()
Do While True
threadCount += 1
If Not loopSwitchValue Then Exit Do
Loop
Console.WriteLine("{0,-11} with {1,11} priority " &
"has a count = {2,13}", Thread.CurrentThread.Name,
Thread.CurrentThread.Priority.ToString(),
threadCount.ToString("N0"))
End Sub
End Class
输出:
ThreadOne with Normal priority has a count = 755,897,581 ThreadThree with AboveNormal priority has a count = 778,099,094 ThreadTwo with BelowNormal priority has a count = 7,840,984