Name 속성을 사용하여 C#에서 현재 스레드의 이름을 표시합니다.
먼저 currentThread 속성을 사용하여 스레드에 대한 정보를 표시합니다. -
Thread thread = Thread.CurrentThread;
이제 thread.Name 속성을 사용하여 스레드의 이름을 표시하십시오 -
thread.Name
C#에서 현재 쓰레드의 이름을 보여주는 완전한 코드를 보자 -
예시
using System;
using System.Threading;
namespace Demo {
class MyClass {
static void Main(string[] args) {
Thread thread = Thread.CurrentThread;
thread.Name = "My Thread";
Console.WriteLine("Thread Name = {0}", thread.Name);
Console.ReadKey();
}
}
} 출력
Thread Name = My Thread