Thread.ThreadState 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
현재 스레드의 상태를 포함하는 값을 가져옵니다.
public:
property System::Threading::ThreadState ThreadState { System::Threading::ThreadState get(); };
public System.Threading.ThreadState ThreadState { get; }
member this.ThreadState : System.Threading.ThreadState
Public ReadOnly Property ThreadState As ThreadState
속성 값
현재 스레드의 ThreadState 상태를 나타내는 값 중 하나입니다. 초기 값은 Unstarted입니다.
예제
다음 코드 예제에서는 스레드의 ThreadState 액세스를 보여 줍니다.
using System;
using System.Threading;
class Example
{
static void Main()
{
Thread newThread =
new Thread(new ThreadStart(ThreadMethod));
Console.WriteLine("ThreadState: {0}", newThread.ThreadState);
newThread.Start();
// Wait for newThread to start and go to sleep.
Thread.Sleep(300);
Console.WriteLine("ThreadState: {0}", newThread.ThreadState);
// Wait for newThread to restart.
Thread.Sleep(1000);
Console.WriteLine("ThreadState: {0}", newThread.ThreadState);
}
static void ThreadMethod()
{
Thread.Sleep(1000);
}
}
// The example displays the following output:
// ThreadState: Unstarted
// ThreadState: WaitSleepJoin
// ThreadState: Stopped
open System.Threading
let threadMethod () =
Thread.Sleep 1000
let newThread = Thread threadMethod
printfn $"ThreadState: {newThread.ThreadState}"
newThread.Start()
// Wait for newThread to start and go to sleep.
Thread.Sleep 300
printfn $"ThreadState: {newThread.ThreadState}"
// Wait for newThread to restart.
Thread.Sleep 1000
printfn $"ThreadState: {newThread.ThreadState}"
// The example displays the following output:
// ThreadState: Unstarted
// ThreadState: WaitSleepJoin
// ThreadState: Stopped
Imports System.Threading
Public Module Example
Public Sub Main()
Dim newThread As Thread = New Thread(AddressOf ThreadMethod)
Console.WriteLine("ThreadState: {0}", newThread.ThreadState)
newThread.Start()
' Wait for newThread to start and go to sleep.
Thread.Sleep(300)
Console.WriteLine("ThreadState: {0}", newThread.ThreadState)
' Wait for newThread to restart.
Thread.Sleep(1000)
Console.WriteLine("ThreadState: {0}", newThread.ThreadState)
End Sub
Sub ThreadMethod()
Thread.Sleep(1000)
End Sub
End Module
' The example displays the following output:
' ThreadState: Unstarted
' ThreadState: WaitSleepJoin
' ThreadState: Stopped
설명
속성은 ThreadState 속성보다 IsAlive 더 구체적인 정보를 제공합니다.
중요합니다
스레드 상태는 디버깅 시나리오에만 관심이 있습니다. 코드는 스레드 상태를 사용하여 스레드 활동을 동기화해서는 안 됩니다.