×

VB.Net Programs

VB.Net program to set and print the name of the current thread

By Nidhi Last Updated : November 16, 2024

Setting and printing the name of the current thread in VB.Net

To solve the above problem, we need to use the Thread class and CurrentThread and Name properties of the Thread class.

Program/Source Code:

The source code to set and print the name of the current thread is given below. The given program is compiled and executed successfully.

VB.Net code to set and print the name of the current thread

'Vb.Net program to set and print the name 
'of the current thread.

Imports System.Threading

Module Module1
    Sub Main()
        Dim t As Thread
        t = Thread.CurrentThread
        t.Name = "MyNewThread"

        Console.WriteLine("Thread information:")
        Console.WriteLine("Name of the thread: " + t.Name)
    End Sub
End Module

Output

Thread information:
Name of the thread: MyNewThread
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 assigned the name of the thread using the Name property and then print the Name of the thread on the console screen.

VB.Net Threading Programs »


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.