Problem solve Get help with specific problems with your technologies, process and projects.

Threading in VB.NET

This example introduces you to using threads and assigning priorities to each thread for execution in VB.NET.

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
 Sub main()
        '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
       Catch e As exception
       End Try
      End Sub

      Shared Sub hi()
        'Infinite Loop CTRL + C to Exit
        Do While True
      End Sub

      Shared Sub bye()
        'Infinite Loop CTRL + C to Exit
         Do While True
      End Sub
   End Class

Other resources for Windows developers: 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 last published in February 2003

Dig Deeper on VB 6 to VB .NET Migration

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.