Home »
VB.Net »
VB.Net Programs
VB.Net program to check the thread is alive or not
By Nidhi Last Updated : October 13, 2024
Checking the thread is alive or not in VB.Net
To solve the above problem, we need to use the IsAlive property of the Thread class, it will return True if the thread is alive.
Program/Source Code:
The source code to check the thread is alive or not is given below. The given program is compiled and executed successfully.
VB.Net code to check whether a thread is alive or not
'Vb.Net program to check the thread is alive or not.
Imports System.Threading
Module Module1
Sub Main()
Dim t As Thread
t = Thread.CurrentThread
t.Name = "MyNewThread"
Console.WriteLine("Thread information:")
Console.WriteLine(vbTab & "Name of the thread: " + t.Name)
If t.IsAlive = True Then
Console.WriteLine(vbTab &"Thread is Alive")
Else
Console.WriteLine(vbTab & "Thread is not Alive")
End If
End Sub
End Module
Output
Thread information:
Name of the thread: MyNewThread
Thread is Alive
Press any key to continue . . .
Explanation
In the above program, we imported the System.Threading namespace to implement multithreading in the program. After that, we created a module Module1. The Module1 contains Main() function.
The Main() is the entry point for the program, we created the reference of Thread class and assigned the object of the current thread using the CurrentThread property. After that, we used the IsAlive property to check the thread status. The IsAlive property will return True if the thread is alive. Otherwise, it will return a False value.
VB.Net Threading Programs »