如何:在托管代码中设置线程名称
更新:2007 年 11 月
本主题适用于:
版本 |
Visual Basic |
C# |
C++ |
Web Developer |
---|---|---|---|---|
速成版 |
||||
标准版 |
||||
专业团队版 |
表格图例:
适用 |
|
不适用 |
|
默认情况下隐藏的一条或多条命令。 |
若要在托管代码中设置线程名称,请使用 [System.Threading.Thread.Name] 属性。
示例
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