Example
using System; using System.Threading; namespace Samples { public class ThreadAbortExceptionSample { public static void StartHere() { try { Console.WriteLine("Thread starting"); Thread.Sleep(1000); Console.WriteLine("Thread finishing"); } catch(ThreadAbortException e) { string s = (string) e.ExceptionState; Console.WriteLine(s); } finally { Console.WriteLine("In finally"); } } public static void Main() { Thread t = new Thread( new ThreadStart(StartHere)); Console.WriteLine("Main starting"); t.Start(); Thread.Sleep(500); t.Abort("Time to go"); t.Join(); Console.WriteLine("Main finishing"); } } }
Main starting Thread starting Time to go In finally Main finishing
Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.