Thread.IsThreadPoolThread Property
.NET Framework 3.0
Gets a value indicating whether or not a thread belongs to the managed thread pool.
Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Thread Members
System.Threading Namespace
ThreadPool
Assembly: mscorlib (in mscorlib.dll)
For more information see The Managed Thread Pool.
The following code example shows how to determine whether a thread is from the thread pool.
using System; using System.Threading; class IsThreadPool { static void Main() { AutoResetEvent autoEvent = new AutoResetEvent(false); Thread regularThread = new Thread(new ThreadStart(ThreadMethod)); regularThread.Start(); ThreadPool.QueueUserWorkItem(new WaitCallback(WorkMethod), autoEvent); // Wait for foreground thread to end. regularThread.Join(); // Wait for background thread to end. autoEvent.WaitOne(); } static void ThreadMethod() { Console.WriteLine("ThreadOne, executing ThreadMethod, " + "is {0}from the thread pool.", Thread.CurrentThread.IsThreadPoolThread ? "" : "not "); } static void WorkMethod(object stateInfo) { Console.WriteLine("ThreadTwo, executing WorkMethod, " + "is {0}from the thread pool.", Thread.CurrentThread.IsThreadPoolThread ? "" : "not "); // Signal that this thread is finished. ((AutoResetEvent)stateInfo).Set(); } }
import System.*;
import System.Threading.*;
import System.Threading.Thread;
class IsThreadPool
{
public static void main(String[] args)
{
AutoResetEvent autoEvent = new AutoResetEvent(false);
Thread regularThread = new Thread(new ThreadStart(ThreadMethod));
regularThread.Start();
ThreadPool.QueueUserWorkItem(new WaitCallback(WorkMethod), autoEvent);
// Wait for foreground thread to end.
regularThread.Join();
// Wait for background thread to end.
autoEvent.WaitOne();
} //main
static void ThreadMethod()
{
Console.WriteLine("ThreadOne, executing ThreadMethod, "
+ "is {0}from the thread pool.",
(Thread.get_CurrentThread().get_IsThreadPoolThread())
? "" : "not ");
} //ThreadMethod
static void WorkMethod(Object stateInfo)
{
Console.WriteLine("ThreadTwo, executing WorkMethod, " +
"is {0}from the thread pool.",
(Thread.get_CurrentThread().get_IsThreadPoolThread())
? "" : "not ");
// Signal that this thread is finished.
((AutoResetEvent)(stateInfo)).Set();
} //WorkMethod
} //IsThreadPool
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.Reference
Thread ClassThread Members
System.Threading Namespace
ThreadPool