共用方式為


HOW TO:在 Managed 程式碼中設定執行緒名稱

這個主題適用於:

版本

Visual Basic

C#

F#

C++

Web Developer

Express

標題適用於 標題適用於 標題適用於 標題適用於 標題適用於

Pro、Premium 和 Ultimate

標題適用於

標題適用於

標題適用於

標題適用於

標題適用於

在所有 Visual Studio 版本中,都可以將執行緒命名。 將執行緒命名後,在 [執行緒] 視窗中追蹤執行緒會很方便。 因為 Visual Studio Express 版本並不提供 [執行緒] 視窗,所以將執行緒命名,在 Express 版本中不太有用。

若要在 Managed 程式碼內設定執行緒名稱,請使用 [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

請參閱

工作

HOW TO:在機器碼中設定執行緒名稱

其他資源

偵錯多執行緒應用程式