Export (0) Print
Expand All

How to: Set a Thread Name in Managed Code

This topic applies to:

Edition

Visual Basic

C#

C++

Web Developer

Express

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

Standard

Topic appliesTopic 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

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

Community Additions

ADD
Show:
© 2014 Microsoft