How to: Set a Thread Name in Managed Code
This topic applies to:
Edition |
Visual Basic |
C# |
C++ |
Web Developer |
---|---|---|---|---|
Express |
||||
Standard |
||||
Pro and Team |
Table legend:
Applies |
|
Does not apply |
|
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