다음을 통해 공유


Thread.IsThreadPoolThread 속성

스레드가 관리되는 스레드 풀에 속하는지 여부를 나타내는 값을 가져옵니다.

네임스페이스: System.Threading
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public ReadOnly Property IsThreadPoolThread As Boolean
‘사용 방법
Dim instance As Thread
Dim value As Boolean

value = instance.IsThreadPoolThread
public bool IsThreadPoolThread { get; }
public:
property bool IsThreadPoolThread {
    bool get ();
}
/** @property */
public boolean get_IsThreadPoolThread ()
public function get IsThreadPoolThread () : boolean

속성 값

이 스레드가 관리되는 스레드 풀에 속하면 true이고, 그렇지 않으면 false입니다.

예제

다음 코드 예제에서는 스레드가 스레드 풀에 포함되어 있는지 여부를 확인하는 방법을 보여 줍니다.

Option Explicit
Option Strict

Imports System
Imports System.Threading

Public Class IsThreadPool

    <MTAThread> _
    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
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();
    }
}
using namespace System;
using namespace System::Threading;
ref class IsThreadPool
{
public:

   static void ThreadMethod()
   {
      Console::WriteLine( "ThreadOne, executing ThreadMethod, "
      "is {0}from the thread pool.", Thread::CurrentThread->IsThreadPoolThread ? (String^)"" : "not " );
   }


   static void WorkMethod( Object^ stateInfo )
   {
      Console::WriteLine( "ThreadTwo, executing WorkMethod, "
      "is {0}from the thread pool.", Thread::CurrentThread->IsThreadPoolThread ? (String^)"" : "not " );
      
      // Signal that this thread is finished.
      dynamic_cast<AutoResetEvent^>(stateInfo)->Set();
   }

};

int main()
{
   AutoResetEvent^ autoEvent = gcnew AutoResetEvent( false );
   Thread^ regularThread = gcnew Thread( gcnew ThreadStart( &IsThreadPool::ThreadMethod ) );
   regularThread->Start();
   ThreadPool::QueueUserWorkItem( gcnew WaitCallback( &IsThreadPool::WorkMethod ), autoEvent );
   
   // Wait for foreground thread to end.
   regularThread->Join();
   
   // Wait for background thread to end.
   autoEvent->WaitOne();
}
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 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

Thread 클래스
Thread 멤버
System.Threading 네임스페이스