Thread.IsThreadPoolThread Property
.NET Framework 1.1
Gets a value indicating whether or not a thread belongs to the managed thread pool.
[Visual Basic] Public ReadOnly Property IsThreadPoolThread As Boolean [C#] public bool IsThreadPoolThread {get;} [C++] public: __property bool get_IsThreadPoolThread(); [JScript] public function get IsThreadPoolThread() : Boolean;
Property Value
true if this thread belongs to the managed thread pool; otherwise, false.
Example
[Visual Basic, C#, C++] The following code example shows how to determine whether a thread is from the thread pool.
[Visual Basic] Option Explicit Option Strict Imports System Imports System.Threading Public Class IsThreadPool Shared Sub Main() Dim autoEvent As New AutoResetEvent(False) Dim regularThread As New Thread(AddressOf ThreadMethod) regularThread.Start() ThreadPool.QueueUserWorkItem(AddressOf WorkMethod, autoEvent) ' Wait for foreground thread to end. regularThread.Join() ' Wait for background thread to end. autoEvent.WaitOne() End Sub Shared Sub ThreadMethod() Console.WriteLine("ThreadOne, executing ThreadMethod, " & _ "is from the thread pool? {0}", _ Thread.CurrentThread.IsThreadPoolThread) End Sub Shared Sub WorkMethod(stateInfo As Object) Console.WriteLine("ThreadTwo, executing WorkMethod, " & _ "is from the thread pool? {0}", _ Thread.CurrentThread.IsThreadPoolThread) ' Signal that this thread is finished. DirectCast(stateInfo, AutoResetEvent).Set() End Sub End Class [C#] 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(); } } [C++] #using <mscorlib.dll> using namespace System; using namespace System::Threading; __gc class IsThreadPool { public: static void ThreadMethod() { Console::WriteLine(S"ThreadOne, executing ThreadMethod, " S"is {0}from the thread pool.", Thread::CurrentThread->IsThreadPoolThread ? S"" : S"not "); } static void WorkMethod(Object* stateInfo) { Console::WriteLine(S"ThreadTwo, executing WorkMethod, " S"is {0}from the thread pool.", Thread::CurrentThread->IsThreadPoolThread ? S"" : S"not "); // Signal that this thread is finished. dynamic_cast<AutoResetEvent*>(stateInfo)->Set(); } }; void main() { AutoResetEvent* autoEvent = new AutoResetEvent(false); Thread* regularThread = new Thread(new ThreadStart(0, &IsThreadPool::ThreadMethod)); regularThread->Start(); ThreadPool::QueueUserWorkItem(new WaitCallback(0, &IsThreadPool::WorkMethod), autoEvent); // Wait for foreground thread to end. regularThread->Join(); // Wait for background thread to end. autoEvent->WaitOne(); }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family