Skip to main content

Multi-Threaded Applications in Visual Basic

Screenshot
Body
Introduction: This tutorial is on how to create a multi-threaded application in Visual Basic. Design: There really is no design needed for this application, although if you wanted to, you can add a button. What Is a Thread? A thread is the part of your .NET program which runs everything else, your UI, your functions and your classes. Without a thread, your program would not be able to run. Why Multiple Threads? Once a thread has a lot of processing to do, problems begin to arrise. The main problem you may see, is your UI freezing. Creating a thread is very easy and should be done to handle any large or process hogging processes. Import: To create a new thread, we must import the namespace...
  1. Imports System.Threading
Creating a Thread: Now, to create a thread we create an object as thread, then assign it to a new thread. A new thread requires one parameter which is 'AddressOf' followed by the function to run once the thread is started.
  1. Dim trd As Thread = New Thread(AddressOf runThread)
Starting a Thread: Once the thread is created, we can start it running the 'AddressOf' function by invoking its 'Start' function...
  1. trd.Start()
runThread Function: Finally we can create our 'runThread' function which is the 'addressOf' our new thread, 'trd'...
  1. Private Function runThread()
  2. MsgBox("Hi there!")
  3. End Function

Add new comment