Multi-Threaded Applications in Visual Basic
Submitted by Yorkiebar on Thursday, April 17, 2014 - 09:41.
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...
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.
Starting a Thread:
Once the thread is created, we can start it running the 'AddressOf' function by invoking its 'Start' function...
runThread Function:
Finally we can create our 'runThread' function which is the 'addressOf' our new thread, 'trd'...
- Imports System.Threading
- Dim trd As Thread = New Thread(AddressOf runThread)
- trd.Start()
- Private Function runThread()
- MsgBox("Hi there!")
- End Function
Add new comment
- 41 views