C# Thread Name
The Name property of the Thread class can be used to change or get the name of the thread.
Example:
using System; using System.Threading; public class Example { public void thrd1() { Thread x = Thread.CurrentThread; Console.WriteLine("The running thread is: " + x.Name); } } public class thrd2 { public static void Main() { Example thrd = new Example(); Thread x = new Thread(new ThreadStart(thrd.thrd1)); Thread y = new Thread(new ThreadStart(thrd.thrd1)); Thread z = new Thread(new ThreadStart(thrd.thrd1)); x.Name = "ONE"; y.Name = "TWO"; z.Name = "THREE"; x.Start(); y.Start(); z.Start(); } } |
Output:
Explanation:
In the above example, we are setting and getting the names of the threads.