using System; using System.Threading; namespace Recetas.Multithreading.Cap01 { internal sealed class UsoAbortObject { public static void Main() { Console.WriteLine(); Thread threadNuevo = new Thread (EjecutarTarea); threadNuevo.Start(); Thread.Sleep (1000); // Aborto del thread `threadNuevo`: Console.WriteLine ("Thread Main abortando el nuevo thread."); threadNuevo.Abort( "Datos desde el thread Main."); // A espera a que el thread `threadNuevo` termine: threadNuevo.Join (); Console.WriteLine ("\nEl thread `threadNuevo` ha finalizado."); Console.WriteLine ("\nEl thread Main a punto de finalizar.\n"); } private static void EjecutarTarea () { try { while (true) { Console.WriteLine ("`threadNuevo` en ejecución..."); Thread.Sleep (1000); } } catch(ThreadAbortException tae) { Console.WriteLine ("\nMensaje excepción: {0}", (string)tae.ExceptionState); } } } }