Introduction:
Here, In this articals we will see how to use Multithreading in vb.net.
Multithreading execute two or more "parts" of a program concurrently Each part is known as a thread. A thread is basically a seprate sequence of instructions designed performing a "specific task" in the program. multithreading means performing tasks at the same time during the execution of a program.
Example:
Imports System.Threading
Public Class AOne
Public Sub first()
Console.WriteLine("First method of Aone class is running on T1 thread.")
Thread.Sleep(1000)
Console.WriteLine("The First method called by T1 thread has ended.")
End Sub
Public Shared Sub second()
Console.WriteLine("First method of Aone class is running on thread.")
Thread.Sleep(2000)
Console.WriteLine("The First method called by T2 thread has ended.")
End Sub
End Class
Public Class ThreadExp
Public Shared Function Main(ByVal args As String()) As Integer
Console.WriteLine("Example of threading")
Dim a As New AOne()
Dim T1 As New Thread(New ThreadStart(AddressOf a.first))
T1.Start()
Console.WriteLine("T1 thread started.")
Dim T2 As New Thread(New ThreadStart(AddressOf AOne.second))
T2.Start()
Console.WriteLine("T2 thread started.")
Return 0
End Function
End Class
Output of program :
![multithreading.gif]()
Thank U. if you have any Suggestions and Comments about my blog, Please let me know. | |