• We just launched and are currently in beta. Join us as we build and grow the community.

Multi-Threaded Applications in Visual Basic

Namanparikh

Code Instrumentation Expert
N Rep
0
0
0
Rep
0
N Vouches
0
0
0
Vouches
0
Posts
80
Likes
88
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
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

 

452,292

323,348

323,357

Top