マネージド コードのスレッド名を設定する

スレッド名の設定は、Visual Studio のどのエディションでも実行できます。 スレッド名を設定すると、[スレッド] ウィンドウでスレッドを追跡する際に役立ちます。

マネージド コードのスレッド名を設定するには、Name プロパティを使用します。

public class Needle
{
    // This method will be called when the thread is started.
    public void Baz()
    {
        Console.WriteLine("Needle Baz is running on another thread");
    }
}

public void Main()
{
    Console.WriteLine("Thread Simple Sample");
    Needle oNeedle = new Needle();
    // Create a Thread object.
    System.Threading.Thread oThread = new System.Threading.Thread(oNeedle.Baz);
    // Set the Thread name to "MyThread".
    oThread.Name = "MyThread";
    // Starting the thread invokes the ThreadStart delegate
    oThread.Start();
}