Thread.ResetAbort() : Thread « System.Threading « C# / C Sharp by API






Thread.ResetAbort()

  

using System; 
using System.Threading; 
 
class MyThread {  
  public Thread thrd;  
    
  public MyThread(string name) {  
    thrd = new Thread(this.run); 
    thrd.Name = name; 
    thrd.Start();  
  }  
  
  void run() {  
    Console.WriteLine(thrd.Name + " starting."); 
 
    for(int i = 1; i <= 100; i++) {  
      try { 
        Console.Write(i + " ");  
        Thread.Sleep(50); 
      } catch(ThreadAbortException exc) { 
        if((int)exc.ExceptionState == 0) { 
          Console.WriteLine("Abort Cancelled! Code is " + exc.ExceptionState); 
          Thread.ResetAbort(); 
        } else  
          Console.WriteLine("Thread aborting, code is " + exc.ExceptionState); 
      } 
    } 
    Console.WriteLine(thrd.Name + " exiting normally.");  
  } 
} 
  
class MainClass {  
  public static void Main() {  
    MyThread mt1 = new MyThread("My Thread");  
 
    Thread.Sleep(1000); 
 
    Console.WriteLine("Stopping thread.");  
    mt1.thrd.Abort(100); 
 
    mt1.thrd.Join(); 
 
    Console.WriteLine("Main thread terminating.");  
  }  
}

   
    
  








Related examples in the same category

1.new Thread()
2.Thread.Abort()
3.Thread.AllocateDataSlot
4.Thread.AllocateNamedDataSlot
5.Thread.CurrentContext
6.Thread.CurrentCulture
7.Thread.CurrentThread
8.Thread.GetData
9.Thread.GetHashCode()
10.Thread.Interrupt()
11.Thread.IsAlive
12.Thread.IsBackground
13.Thread.Join()
14.Thread.Priority
15.Thread.SetData
16.Thread.Sleep
17.Thread.Start
18.Thread.ThreadState