ThreadAbortException 클래스
정의
Abort(Object) 메서드를 호출할 때 throw되는 예외입니다.The exception that is thrown when a call is made to the Abort(Object) method. 이 클래스는 상속될 수 없습니다.This class cannot be inherited.
public ref class ThreadAbortException sealed : SystemException
public sealed class ThreadAbortException : SystemException
[System.Serializable]
public sealed class ThreadAbortException : SystemException
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class ThreadAbortException : SystemException
type ThreadAbortException = class
inherit SystemException
[<System.Serializable>]
type ThreadAbortException = class
inherit SystemException
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ThreadAbortException = class
inherit SystemException
Public NotInheritable Class ThreadAbortException
Inherits SystemException
- 상속
- 특성
예제
다음 예제에서는 스레드를 중단 하는 방법을 보여 줍니다.The following example demonstrates aborting a thread. 를 수신 하는 스레드는 ThreadAbortException
메서드를 사용 하 여 ResetAbort abort 요청을 취소 하 고 계속 실행 합니다.The thread that receives the ThreadAbortException
uses the ResetAbort method to cancel the abort request and continue executing.
using namespace System;
using namespace System::Threading;
using namespace System::Security::Permissions;
ref class ThreadWork
{
public:
static void DoWork()
{
try
{
for ( int i = 0; i < 100; i++ )
{
Console::WriteLine( "Thread - working." );
Thread::Sleep( 100 );
}
}
catch ( ThreadAbortException^ e )
{
Console::WriteLine( "Thread - caught ThreadAbortException - resetting." );
Console::WriteLine( "Exception message: {0}", e->Message );
Thread::ResetAbort();
}
Console::WriteLine( "Thread - still alive and working." );
Thread::Sleep( 1000 );
Console::WriteLine( "Thread - finished working." );
}
};
int main()
{
ThreadStart^ myThreadDelegate = gcnew ThreadStart( ThreadWork::DoWork );
Thread^ myThread = gcnew Thread( myThreadDelegate );
myThread->Start();
Thread::Sleep( 100 );
Console::WriteLine( "Main - aborting my thread." );
myThread->Abort();
myThread->Join();
Console::WriteLine( "Main ending." );
}
using System;
using System.Threading;
using System.Security.Permissions;
public class ThreadWork {
public static void DoWork() {
try {
for(int i=0; i<100; i++) {
Console.WriteLine("Thread - working.");
Thread.Sleep(100);
}
}
catch(ThreadAbortException e) {
Console.WriteLine("Thread - caught ThreadAbortException - resetting.");
Console.WriteLine("Exception message: {0}", e.Message);
Thread.ResetAbort();
}
Console.WriteLine("Thread - still alive and working.");
Thread.Sleep(1000);
Console.WriteLine("Thread - finished working.");
}
}
class ThreadAbortTest {
public static void Main() {
ThreadStart myThreadDelegate = new ThreadStart(ThreadWork.DoWork);
Thread myThread = new Thread(myThreadDelegate);
myThread.Start();
Thread.Sleep(100);
Console.WriteLine("Main - aborting my thread.");
myThread.Abort();
myThread.Join();
Console.WriteLine("Main ending.");
}
}
Imports System.Threading
Imports System.Security.Permissions
Public Class ThreadWork
Public Shared Sub DoWork()
Try
Dim i As Integer
For i = 0 To 99
Console.WriteLine("Thread - working.")
Thread.Sleep(100)
Next i
Catch e As ThreadAbortException
Console.WriteLine("Thread - caught ThreadAbortException - resetting.")
Console.WriteLine("Exception message: {0}", e.Message)
Thread.ResetAbort()
End Try
Console.WriteLine("Thread - still alive and working.")
Thread.Sleep(1000)
Console.WriteLine("Thread - finished working.")
End Sub
End Class
Class ThreadAbortTest
Public Shared Sub Main()
Dim myThreadDelegate As New ThreadStart(AddressOf ThreadWork.DoWork)
Dim myThread As New Thread(myThreadDelegate)
myThread.Start()
Thread.Sleep(100)
Console.WriteLine("Main - aborting my thread.")
myThread.Abort()
myThread.Join()
Console.WriteLine("Main ending.")
End Sub
End Class
이 코드의 결과는 다음과 같습니다.This code produces the following output:
Thread - working.
Main - aborting my thread.
Thread - caught ThreadAbortException - resetting.
Exception message: Thread was being aborted.
Thread - still alive and working.
Thread - finished working.
Main ending.
설명
Abort스레드를 삭제 하기 위해 메서드가 호출 되 면 공용 언어 런타임에서이 throw 됩니다 ThreadAbortException .When a call is made to the Abort method to destroy a thread, the common language runtime throws a ThreadAbortException. ThreadAbortException 는 catch 할 수 있는 특별 한 예외 이지만 블록 끝에서 자동으로 다시 발생 catch
합니다.ThreadAbortException is a special exception that can be caught, but it will automatically be raised again at the end of the catch
block. 이 예외가 발생 하면 런타임은 finally
스레드를 종료 하기 전에 모든 블록을 실행 합니다.When this exception is raised, the runtime executes all the finally
blocks before ending the thread. 스레드는 블록에서 바인딩되지 않은 계산을 수행 finally
하거나 abort를 취소 하기 위해를 호출할 수 있으므로 스레드가 종료 되지 않을 수도 있습니다 Thread.ResetAbort .Because the thread can do an unbounded computation in the finally
blocks or call Thread.ResetAbort to cancel the abort, there is no guarantee that the thread will ever end. 중단 된 스레드가 종료 될 때까지 대기 하려면 메서드를 호출 하면 Thread.Join 됩니다.If you want to wait until the aborted thread has ended, you can call the Thread.Join method. Join 는 스레드가 실제로 실행을 중지할 때까지 반환 되지 않는 차단 호출입니다.Join is a blocking call that does not return until the thread actually stops executing.
.Net Core만: 가 지원 되지 않으므로이 형식이 .NET Core에 있는 경우에도 Abort 공용 언어 런타임은 throw 되지 않습니다 ThreadAbortException ..NET Core only: Even though this type exists in .NET Core, since Abort is not supported, the common language runtime won't ever throw ThreadAbortException.
참고
CLR (공용 언어 런타임)이 관리 되는 실행 파일의 모든 포그라운드 스레드가 종료 된 후 백그라운드 스레드를 중지 하면를 사용 하지 않습니다 Thread.Abort .When the common language runtime (CLR) stops background threads after all foreground threads in a managed executable have ended, it does not use Thread.Abort. 따라서를 사용 하 여 ThreadAbortException CLR에서 백그라운드 스레드를 종료 하는 시기를 감지할 수 없습니다.Therefore, you cannot use ThreadAbortException to detect when background threads are being terminated by the CLR.
ThreadAbortException 는 0x80131530 값을 갖는 HRESULT COR_E_THREADABORTED를 사용 합니다.ThreadAbortException uses the HRESULT COR_E_THREADABORTED, which has the value 0x80131530.
속성
Data |
예외에 대한 사용자 정의 정보를 추가로 제공하는 키/값 쌍 컬렉션을 가져옵니다.Gets a collection of key/value pairs that provide additional user-defined information about the exception. (다음에서 상속됨 Exception) |
ExceptionState |
스레드 중단에 관련된 애플리케이션 관련 정보가 포함된 개체를 가져옵니다.Gets an object that contains application-specific information related to the thread abort. |
HelpLink |
이 예외와 연결된 도움말 파일에 대한 링크를 가져오거나 설정합니다.Gets or sets a link to the help file associated with this exception. (다음에서 상속됨 Exception) |
HResult |
특정 예외에 할당된 코드화된 숫자 값인 HRESULT를 가져오거나 설정합니다.Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception. (다음에서 상속됨 Exception) |
InnerException |
현재 예외를 발생시킨 Exception 인스턴스를 가져옵니다.Gets the Exception instance that caused the current exception. (다음에서 상속됨 Exception) |
Message |
현재 예외를 설명하는 메시지를 가져옵니다.Gets a message that describes the current exception. (다음에서 상속됨 Exception) |
Source |
오류를 발생시키는 애플리케이션 또는 개체의 이름을 가져오거나 설정합니다.Gets or sets the name of the application or the object that causes the error. (다음에서 상속됨 Exception) |
StackTrace |
호출 스택의 직접 실행 프레임 문자열 표현을 가져옵니다.Gets a string representation of the immediate frames on the call stack. (다음에서 상속됨 Exception) |
TargetSite |
현재 예외를 throw하는 메서드를 가져옵니다.Gets the method that throws the current exception. (다음에서 상속됨 Exception) |
메서드
Equals(Object) |
지정된 개체가 현재 개체와 같은지 확인합니다.Determines whether the specified object is equal to the current object. (다음에서 상속됨 Object) |
GetBaseException() |
파생 클래스에서 재정의된 경우 하나 이상의 후속 예외의 근본 원인이 되는 Exception 을 반환합니다.When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions. (다음에서 상속됨 Exception) |
GetHashCode() |
기본 해시 함수로 작동합니다.Serves as the default hash function. (다음에서 상속됨 Object) |
GetObjectData(SerializationInfo, StreamingContext) |
파생 클래스에서 재정의된 경우 예외에 관한 정보를 SerializationInfo 에 설정합니다.When overridden in a derived class, sets the SerializationInfo with information about the exception. (다음에서 상속됨 Exception) |
GetType() |
현재 인스턴스의 런타임 형식을 가져옵니다.Gets the runtime type of the current instance. (다음에서 상속됨 Exception) |
MemberwiseClone() |
현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object. (다음에서 상속됨 Object) |
ToString() |
현재 예외에 대한 문자열 표현을 만들고 반환합니다.Creates and returns a string representation of the current exception. (다음에서 상속됨 Exception) |
이벤트
SerializeObjectState |
예외에 대한 serialize된 데이터가 들어 있는 예외 상태 개체가 만들어지도록 예외가 serialize될 때 발생합니다.Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception. (다음에서 상속됨 Exception) |