Share via


How to: Set a Thread Name (Managed) 

This topic applies to:

Visual Studio Edition

Visual Basic

C#

C++

J#

Web Dev

Express Edition

No

No

No

No

No

Standard Edition

Yes

Yes

Yes

Yes

Yes

Pro/Team Edition

Yes

Yes

Yes

Yes

Yes

To set a thread name in managed code, use the Thread.Name property of the .NET Framework Thread class.

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: Use the Threads Window
How to: Set a Thread Name (Unmanaged)

Reference

Thread.Name Property
Thread Class

Concepts

Viewing Data in the Debugger