Comment : définir un nom de thread dans le code managéHow to: Set a Thread Name in Managed Code

Il est possible d'attribuer des noms aux threads dans toutes les éditions de Visual Studio.Thread naming is possible in any edition of Visual Studio. Ces noms sont utiles pour effectuer le suivi des threads dans le Threads fenêtre.Thread naming is useful for keeping track of threads in the Threads window.

Pour définir un nom de thread en code managé, utilisez la propriété Name.To set a thread name in managed code, use the Name property.

ExempleExample

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();
}
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 "MyThread".  
    oThread.Name = "MyThread"  
    ' Starting the thread invokes the ThreadStart delegate  
    oThread.Start()  
End Sub  

Voir aussiSee Also

Débogage d’Applications multithread Debug Multithreaded Applications
Guide pratique pour définir un nom de thread dans du code natifHow to: Set a Thread Name in Native Code