ThreadAbortException.ExceptionState 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
스레드 중단과 관련된 애플리케이션별 정보를 포함하는 개체를 가져옵니다.
public:
property System::Object ^ ExceptionState { System::Object ^ get(); };
public object ExceptionState { get; }
member this.ExceptionState : obj
Public ReadOnly Property ExceptionState As Object
속성 값
애플리케이션 관련 정보를 포함하는 개체입니다.
예제
다음 코드 예제에서는 중단 중인 스레드에 정보를 전달하는 방법을 보여줍니다.
using System;
using System.Threading;
class Test
{
public static void Main()
{
Thread newThread = new Thread(new ThreadStart(TestMethod));
newThread.Start();
Thread.Sleep(1000);
// Abort newThread.
Console.WriteLine("Main aborting new thread.");
newThread.Abort("Information from Main.");
// Wait for the thread to terminate.
newThread.Join();
Console.WriteLine("New thread terminated - Main exiting.");
}
static void TestMethod()
{
try
{
while(true)
{
Console.WriteLine("New thread running.");
Thread.Sleep(1000);
}
}
catch(ThreadAbortException abortException)
{
Console.WriteLine((string)abortException.ExceptionState);
}
}
}
Imports System.Threading
Public Class Test
<MTAThread> _
Shared Sub Main()
Dim newThread As New Thread(AddressOf TestMethod)
newThread.Start()
Thread.Sleep(1000)
' Abort newThread.
Console.WriteLine("Main aborting new thread.")
newThread.Abort("Information from Main.")
' Wait for the thread to terminate.
newThread.Join()
Console.WriteLine("New thread terminated - Main exiting.")
End Sub
Shared Sub TestMethod()
Try
While True
Console.WriteLine("New thread running.")
Thread.Sleep(1000)
End While
Catch abortException As ThreadAbortException
Console.WriteLine( _
CType(abortException.ExceptionState, String))
End Try
End Sub
End Class
설명
이 속성에서 반환된 개체는 메서드의 Abort 매개 변수를 stateInfo 통해 지정됩니다. 이 개체의 정확한 내용과 사용법은 애플리케이션에서 정의됩니다. 일반적으로 중단되는 스레드에 의미 있는 정보를 전달하는 데 사용됩니다.