새 스레드를 만들려면.
Thread thread = Thread.CurrentThread; thread.Name = "My new Thread”;
현재 컨텍스트 ID를 얻으려면 ContextID 속성을 사용하십시오.
Thread.CurrentContext.ContextID
전체 코드를 보자 -
예시
using System;
using System.Threading;
namespace Demo {
class MyClass {
static void Main(string[] args) {
Thread thread = Thread.CurrentThread;
thread.Name = "My new Thread";
Console.WriteLine("Thread Name = {0}", thread.Name);
Console.WriteLine("current Context id: {0}", Thread.CurrentContext.ContextID);
Console.ReadKey();
}
}
} 출력
Thread Name = My new Thread current Context id: 0