Thread Priority

Thread class's ThreadPriority property is used to sets thread's priority. The thread priority can have Normal, AboveNormal, BelowNormal, Highest, and Lowest values.

thread.Priority = ThreadPriority.Lowest

Here's a simple example without priority and its output.

Imports System.Threading

Module Module1

Sub Main()

Dim th As New Thread(AddressOf WriteY)

th.Start()

For i As Integer = 0 To 10

Console.WriteLine("Hello")

Next

End Sub

Private Sub WriteY()

For i As Integer = 0 To 9

Console.WriteLine("world")

Next

End Sub

End Module

OUTPUT


th6.gif

Using With Lowest Priority

Imports System.Threading

Module Module1

Sub Main()

Dim th As New Thread(AddressOf WriteY)

th.Priority = ThreadPriority.Lowest

th.Start()

For i As Integer = 0 To 10

Console.WriteLine("Hello")

Next

End Sub

Private Sub WriteY()

For i As Integer = 0 To 9

Console.WriteLine("world")

Next

End Sub

End Module

OUTPUT


th5.gif

In the above example defines the priority, The without priority example execute the method writeY() but in the second example we defines the lowest priority it will execute main method first.