本文整理匯總了VB.NET中System.Threading.ThreadPriority枚舉的典型用法代碼示例。如果您正苦於以下問題:VB.NET ThreadPriority枚舉的具體用法?VB.NET ThreadPriority怎麽用?VB.NET ThreadPriority使用的例子?那麽, 這裏精選的枚舉代碼示例或許可以為您提供幫助。
在下文中一共展示了ThreadPriority枚舉的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