BCL mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.SystemException System.Runtime.InteropServices.ComVisible(true)

The following example demonstrates aborting a thread. The thread that receives the uses the method to cancel the abort request and continue executing.

`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."); 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."); } }`

The output is

Thread - working.

Main - aborting my thread.

Thread - caught ThreadAbortException - resetting.

Thread - still alive and working.

Thread - finished working.

Main ending.

When a call is made to the method to destroy a thread, the common language runtime throws a . is a special exception that can be caught, but it will automatically be raised again at the end of the catch block. When this exception is raised, the runtime executes all the finally blocks before ending the thread. Because the thread can do an unbounded computation in the finally blocks or call to cancel the abort, there is no guarantee that the thread will ever end. If you want to wait until the aborted thread has ended, you can call the method. is a blocking call that does not return until the thread actually stops executing.

When the common language runtime (CLR) stops background threads after all foreground threads in a managed executable have ended, it does not use . Therefore, you cannot use to detect when background threads are being terminated by the CLR.

uses the HRESULT COR_E_THREADABORTED, which has the value 0x80131530.

The value of the inherited property is always null.

The exception that is thrown when a call is made to the method. This class cannot be inherited.

- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Object

  A .

  The object returned by this property is specified through the parameter of the method. The exact content and usage of this object is application defined; it is typically used to convey information that is meaningful to the thread being aborted.

  Gets an object that contains application-specific information related to the thread abort.

  0
0