Developing a multi-threading application in VB.NET is simple. This tutorial is directed to beginners who want to get involved into the multithreading application development. First, let's define the threading namespace:
Imports System.Threading
Using the Thread class of the System.Threading namespace to create, pause, delete, of resume a thread. Let create a thread:
Use the "Start" method to start the thread:
Private MyThread as Thread = New Thread(New ThredStart(TestThread))
MyThread.Start()
TestThread is a Sub executed by all thread
In order to aboard a running thread, use the Abort method. Before you use it, make sure the thread is alive:
Sub TestThread()
Dim strThread as String
Dim i as integer
For i =0 To 1000
strThread="Thread Number: " & i.ToString()
Comsole.WriteLine(strThread)
Next
End Sub
A Sleep method using to pause a thread:
If MyThread.IsAlive Then
MyThread.Abort()
End If
MyThread.Sleep()
To set up a thread priority, use the Priority method from the Thread class. ThreadPriproty property is used to set a thread pripority.Values of this property are: Normal, AboveNorma, BelowNormal, Highest, and Lowest. Here is an example of setting up a therad priority:
Private MyThread.Priority = ThreadPriority.Lowest
The Suspend method is used to suspend a thread. The thread remains suspended until Resume method is called. Suspend and Resume are methods of the Thread Class. Here is an example to suspend a thread:
If MyThread.ThreadState = ThreadState.Running Then
MyThread.Suspend()
End If
And to resume a thread:
If MyThread.ThreadState = ThreadState.Suspended Then
MyThread.Resume()
End If
That's it!!



