Raises a System.Threading.ThreadAbortException in the thread on which it is invoked to begin the process of terminating the thread. In all but the most extraordinary situations, calling this method will terminate the thread.
Permissions
Type Reason !:System.Security.SecurityPermission Requires permission to control the thread to be aborted. See System.Security.Permissions.SecurityPermissionFlag.ControlThread.
Exceptions
Type Reason System.Security.SecurityException Caller does not have System.Security.Permissions.SecurityPermissionFlag.ControlThread security permission for the thread to be aborted.
RemarksWhen this method is invoked on a thread, the system throws a System.Threading.ThreadAbortException in the thread to abort it. Invoking Thread.Abort(object) on a thread is similar to arranging for the target thread to throw a System.Threading.ThreadAbortException. Because, unlike other exceptions, a System.Threading.ThreadAbortException is sent to another thread, the exception might be delayed. A System.Threading.ThreadAbortException is required to be delayed if and while the target thread is executing any of the following:
- unmanaged code
- a catch handler
- a finally clause
- a filter clause
- a type initializer
A thread abort proceeds as follows:
An abort begins at the earliest of the following times:
a. when the thread transitions from unmanaged to managed code execution;
b. when the thread finishes the outermost currently executing catch handler;
c. immediately if the thread is running managed code outside of any catch handler, finally clause, filter clause or type initializer
- Whenever an outermost catch handler finishes execution, the System.Threading.ThreadAbortException is rethrown unless the thread being aborted has called Thread.ResetAbort since the call to Thread.Abort(object).
- When all finally blocks have been called and the thread is about to transition to any unmanaged code which executed before the first entry to managed code, Thread.ResetAbort is called so that a return to managed code will consider the abort to have been successfully processed.
Unexecuted finally blocks are executed before the thread is aborted; this includes any finally block that is executing when the exception is thrown. The thread is not guaranteed to abort immediately, or at all. This situation can occur if a thread does an unbounded amount of computation in the finally blocks that are called as part of the abort procedure, thereby indefinitely delaying the abort. To ensure a thread has aborted, invoke Thread.Join on the thread after calling Thread.Abort(object) .
If Thread.Abort(object) is called on a thread that has not been started, the thread aborts when Thread.Start is called. If the target thread is blocked or sleeping in managed code and is not inside any of the code blocks that are required to delay an abort, the thread is resumed and immediately aborted.
After Thread.Abort(object) is invoked on a thread, the state of the thread includes ThreadState.AbortRequested. After the thread has terminated as a result of a successful call to Thread.Abort(object), the state of the thread includes ThreadState.Stopped and ThreadState.Aborted .
Note: With sufficient permissions, a thread that is the target of a Thread.Abort(object) can cancel the abort using the Thread.ResetAbort method. For an example that demonstrates calling the Thread.ResetAbort method, see System.Threading.ThreadAbortException .
RequirementsNamespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0