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:
using System;
using System.Threading;
class GFG {
static public void Main()
{
Thread T;
T = Thread.CurrentThread;
Console.WriteLine( "Is main thread belongs to Thread" +
" pool? : {0} " , T.IsThreadPoolThread);
}
}
|
Output:
Is main thread belongs to Thread pool? : False
Example 2:
using System;
using System.Threading;
class GFG {
public static void Main()
{
Thread TR1 = new Thread( new ThreadStart(job));
ThreadPool.QueueUserWorkItem( new WaitCallback(job1));
TR1.Start();
}
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);
}
}
|
Output:
Is thread 1 belongs to thread pool: False
Is thread 2 belongs to thread pool: True
Reference: