You can abort a thread by using the Abort method, and you can cancel the abort of the thread by using the ResetAbort method .
The following example demonstrates the use of the abort and ResetAbort methods .
<span style= "FONT-SIZE:14PX;" >using system;using System.threading;namespace abortandresetabortexp{class Program {static void Main (str Ing[] args) {thread t = new Thread (DoWork); T.name = "Eight commandments"; T.start (); Thread.Sleep (10000); Console.WriteLine ("Goku: Eight commandments, it's time to get Up"); T.abort (); } static void DoWork () {try {while (true) { Console.WriteLine (Thread.CurrentThread.Name + ": Whistling ~~~~~"); Thread.Sleep (1000); }} catch (ThreadAbortException e) {Console.WriteLine (Thread.currentthrea D.name + ": Early, I have to sleep again"); Thread.resetabort (); } for (int i = 0; i < i++) {Console.WriteLine (Thread.CurrentThread.Name + ": Call Call ~~~~~ "); Thread.Sleep (1000); } } }}</span>
instance, the main thread initiates the "eight commandments" threads, making it "whirring" to sleep. Ten seconds, the main thread calls the "eight commandments" thread Abort method aborts the "eight commandments" thread, and the "Eight commandments" thread Abort is triggered when the method is called ThreadAbortException exception, after the "eight commandments" thread catches the exception, use the ResetAbort method to cancel the abort of the thread, because he hasn't slept enough yet.
As shown in the execution of the entire program, it can be seen from the results that the thread is still executing after the ResetAbort method is called.
C # multithreaded Development 4: Thread abort and ResetAbort methods