To check if a thread belongs to managed thread pool or not, the code is as follows −
Example
using System;
using System.Threading;
public class Demo {
public static void Main() {
Thread thread = new Thread(new ThreadStart(demo));
thread.Start();
}
public static void demo() {
Console.WriteLine("Thread belongs to managed thread pool? = "+Thread.CurrentThread.IsThreadPoolThread);
}
}Output
This will produce the following output −
Thread belongs to managed thread pool? = False
Example
Let us see another example −
using System;
using System.Threading;
public class Demo {
public static void Main() {
ThreadPool.QueueUserWorkItem(new WaitCallback(demo));
}
public static void demo(object stateInfo) {
Console.WriteLine("Thread belongs to managed thread pool? = "+Thread.CurrentThread.IsThreadPoolThread);
}
}Output
This will produce the following output −
Thread belongs to managed thread pool? = True