वर्तमान में प्रबंधित थ्रेड के लिए विशिष्ट पहचानकर्ता प्राप्त करने के लिए, कोड इस प्रकार है -
उदाहरण
using System;
using System.Threading;
public class Demo {
public static void Main(){
Thread thread = new Thread(new ThreadStart(demo1));
ThreadPool.QueueUserWorkItem(new WaitCallback(demo2));
Console.WriteLine("ManagedThreadId = "+thread.ManagedThreadId);
}
public static void demo1(){
Thread.Sleep(2000);
}
public static void demo2(object stateInfo){
Console.WriteLine("Thread belongs to managed thread pool? = "+Thread.CurrentThread.IsThreadPoolThread);
}
} आउटपुट
यह निम्नलिखित आउटपुट देगा -
ManagedThreadId = 3 Thread belongs to managed thread pool? = True
उदाहरण
आइए अब एक और उदाहरण देखें -
using System;
using System.Threading;
public class Demo {
public static void Main(){
Thread thread = new Thread(new ThreadStart(demo));
Console.WriteLine("ManagedThreadId = "+thread.ManagedThreadId);
thread.Start();
}
public static void demo(){
Console.WriteLine("Thread belongs to managed thread pool? = "+Thread.CurrentThread.IsThreadPoolThread);
}
} आउटपुट
यह निम्नलिखित आउटपुट देगा -
ManagedThreadId = 3 Thread belongs to managed thread pool? = False