How to: Set a Thread Name in Managed Code

This topic applies to:

Edition

Visual Basic

C#

C++

Web Developer

Express

Topic does not apply Topic does not apply Topic does not apply Topic does not apply

Standard

Topic applies Topic applies

Topic applies

Topic applies

Pro and Team

Topic applies

Topic applies

Topic applies

Topic applies

Table legend:

Topic applies

Applies

Topic does not apply

Does not apply

Topic applies but command hidden by default

Command or commands hidden by default.

To set a thread name in managed code, use the [System.Threading.Thread.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

Debugging Multithreaded Applications