Option Explicit On Option Strict On
Imports System Imports System.Threading
Public Class Test
Shared Sub Main() Dim priorityTest As New PriorityTest() Dim threadOne As Thread = New Thread(AddressOf priorityTest.ThreadMethod) threadOne.Name = "ThreadOne" Dim threadTwo As Thread = New Thread(AddressOf priorityTest.ThreadMethod) threadTwo.Name = "ThreadTwo" threadOne.Priority = ThreadPriority.Highest threadTwo.Priority = ThreadPriority.Lowest
threadOne.Start() threadTwo.Start() Thread.Sleep(8000) priorityTest.LoopSwitch = False Console.ReadLine() End Sub
End Class
Public Class PriorityTest
Dim loopSwitchValue As Boolean
Sub New() loopSwitchValue = True End Sub
WriteOnly Property LoopSwitch() As Boolean Set(ByVal value As Boolean) loopSwitchValue = Value End Set End Property
Sub ThreadMethod()
Dim threadCount As Long = 0 While loopSwitchValue threadCount += 1 End While
Console.WriteLine("{0} with {1,11} priority " & _ "has a count = {2,13}", Thread.CurrentThread.Name, _ Thread.CurrentThread.Priority.ToString(), _ threadCount.ToString("N0")) End Sub
End Class
'优先级别一共分以下5种 不指定默认为Normal
Highest
AboveNormal
Normal
BelowNormal
Lowest
|