How to: Set a Thread Name in Managed Code

Thread naming is possible in any edition of Visual Studio. Thread naming is useful for keeping track of threads in the Threads window. Because the Threads window is not available in the Visual Studio Express editions, thread naming has little utility in Express editions.

To set a thread name in managed code, use the Name property.

Example

Public Class Needle
    ' This method will be called when the thread is started.
    Sub Baz()
        Console.WriteLine("Needle Baz is running on another thread")
    End Sub
End Class

Sub Main()
    Console.WriteLine("Thread Simple Sample")
    Dim oNeedle As New Needle()
   ' Create a Thread object. 
    Dim oThread As New System.Threading.Thread(AddressOf oNeedle.Baz)
    ' Set the Thread name to "MainThread".
    oThread.Name = "MainThread"
    ' Starting the thread invokes the ThreadStart delegate
    oThread.Start()
End Sub

See Also

Tasks

How to: Set a Thread Name in Native Code

Other Resources

Debug Multithreaded Applications in Visual Studio