Check if a thread belongs to managed thread pool or not in C#

CsharpServer Side ProgrammingProgramming

To check if a thread belongs to managed thread pool or not, the code is as follows −

Example

 Live Demo

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
raja
Published on 06-Dec-2019 12:29:34
Advertisements