Home »
VB.Net »
VB.Net Programs
VB.Net program to assign the name of a thread
By Nidhi Last Updated : October 13, 2024
Assigning thread's name in VB.Net
Here, we used the Name property Thread class. The Name property is used to set or get the name of the thread.
Program/Source Code:
The source code to assign the name of a thread is given below. The given program is compiled and executed successfully.
VB.Net code to assign the name of a thread
'Vb.Net program to assign the name of a thread.
Imports System.Threading
Module Module1
Sub Main()
If (Thread.CurrentThread.Name = "") Then
Thread.CurrentThread.Name = "MyMainThread"
Console.WriteLine("Name of the thread assigned successfully")
Else
Console.WriteLine("Name of thread already assigned")
End If
End Sub
End Module
Output
Name of the thread assigned successfully
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, here we checked if the Name property contains a "null" value then we assigned the MyMainThread name to the current thread otherwise we print "Name of thread already assigned" on the console screen.
VB.Net Threading Programs »