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


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

Updated on: 06-Dec-2019

118 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements