Thread.IsThreadPoolThread プロパティ
スレッドがマネージ スレッド プールに所属しているかどうかを示す値を取得します。
Public ReadOnly Property IsThreadPoolThread As Boolean
[C#]
public bool IsThreadPoolThread {get;}
[C++]
public: __property bool get_IsThreadPoolThread();
[JScript]
public function get IsThreadPoolThread() : Boolean;
プロパティ値
このスレッドがマネージ スレッド プールに所属している場合は true 。それ以外の場合は false 。
使用例
[Visual Basic, C#, C++] スレッドがスレッド プールに属するものであるかどうかを判断する方法の例を次に示します。
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ