At last Visual Basic incorporates a taste of free threading. The concept of threading has always fascinated me. And now, all the goodies threads have can be accessed in VB.NET in a very simple fashion. This example introduces you to using threads and assigning priorities to each thread for execution:
Option Strict Off
Imports System
Imports Microsoft.VisualBasic
Imports System.Threading
Class MyThread
Shared
Sub main()
Try
'Declare a Thread and Assign it to a Methord Hi
Dim t As New thread(AddressOf hi)
'Declare Another Thread and assign it to Bye
Dim b As New thread(AddressOf bye)
'Set the priority level for each thread
t.Priority = ThreadPriority.Normal
b.Priority = ThreadPriority.Lowest
'Start the thread execution
t.start()
b.start()
Catch e As exception
msgbox(e.tostring)
End Try
End Sub
Shared Sub hi()
'Infinite Loop CTRL + C to Exit
Do While True
console.writeline("hi")
Loop
End Sub
Shared Sub bye()
'Infinite Loop CTRL + C to Exit
Do While True
console.writeline("bye")
Loop
End Sub
End Class
Other resources for Windows developers:
SearchWinDevelopment.com also provides Windows
development tutorials that could help you better understand and utilize Windows development
tools. If you're new to using development tools like Visual Studio,
you might want to check out our insider
guide to Visual Studio 2010, take a look at Visual
Studio navigation tips, or get some help taming the Visual
Studio help engine.
This was first published in February 2003