Skip to content
Related Articles

Related Articles

C# | Check if a thread belongs to managed thread pool or not
  • Last Updated : 01 Feb, 2019

A Thread class is responsible for creating and managing a thread in multi-thread programming. It provides a property known as IsThreadPoolThread to check if the thread belongs to the managed thread pool or not.

Syntax:

public bool IsThreadPoolThread { get; }

Return Value: This property returns true if the given thread belongs to the managed thread pool. Otherwise, return false. The return type of this property is System.Boolean.

Below programs illustrate the use of IsThreadPoolThread property:

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to illustrate the use 
// of IsThreadPoolThread  property
using System;
using System.Threading;
  
class GFG {
  
    // Main Method
    static public void Main()
    {
        Thread T;
  
        // Get the reference of main Thread
        // Using CurrentThread property
        T = Thread.CurrentThread;
  
        // Check if the main thread belongs to
        // the managed thread pool or not
        // Using IsThreadPoolThread  property
        Console.WriteLine("Is main thread belongs to Thread"+
                      " pool? : {0} ", T.IsThreadPoolThread);
    }
}

chevron_right


Output:

Is main thread belongs to Thread pool? : False 

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to illustrate the use
//  of IsThreadPoolThread  property
using System;
using System.Threading;
  
class GFG {
  
    // Main method
    public static void Main()
    {
  
        // Creating and initializing threads
        Thread TR1 = new Thread(new ThreadStart(job));
        ThreadPool.QueueUserWorkItem(new WaitCallback(job1));
        TR1.Start();
    }
  
    // Static methods
    public static void job()
    {
        Console.WriteLine("Is thread 1 belongs to thread pool: {0}",
                           Thread.CurrentThread.IsThreadPoolThread);
    }
  
    public static void job1(object stateInfo)
    {
        Console.WriteLine("Is thread 2 belongs to thread pool: {0}",
                           Thread.CurrentThread.IsThreadPoolThread);
    }
}

chevron_right


Output:

Is thread 1 belongs to thread pool: False
Is thread 2 belongs to thread pool: True

Reference:

My Personal Notes arrow_drop_up
Recommended Articles
Page :