एक नया थ्रेड बनाने के लिए:
Thread thread = Thread.CurrentThread; thread.Name = "My new Thread";
वर्तमान कॉन्टेक्स्ट आईडी प्राप्त करने के लिए, 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