using System;
using System.Threading;
namespace Recetas.Multithreading.Cap01
{
internal sealed class UsoBasicoThreadAbort
{
public static void Main()
{
Thread nuevoThread = new Thread(
delegate()
{
Console.WriteLine ("\nDentro del thread `nuevoThread`...");
// Ciclo infinito...
// Será interrumpido por nuevoThread.Abort() en
// el thread Main:
while(true);
}
);
nuevoThread.Start();
// Permite que el thread nuevoThread se ejecute
// durante 2 segundos:
Thread.Sleep (2000);
// Aborta la ejecución del thread:
nuevoThread.Abort();
Console.WriteLine ();
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGhyZWFkaW5nOwoKbmFtZXNwYWNlIFJlY2V0YXMuTXVsdGl0aHJlYWRpbmcuQ2FwMDEKewogICAgaW50ZXJuYWwgc2VhbGVkIGNsYXNzIFVzb0Jhc2ljb1RocmVhZEFib3J0CiAgICB7CiAgICAgICAgcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQogICAgICAgIHsKICAgICAgICAgICAgVGhyZWFkIG51ZXZvVGhyZWFkID0gbmV3IFRocmVhZCgKICAgICAgICAgICAgICAgIGRlbGVnYXRlKCkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSAoIlxuRGVudHJvIGRlbCB0aHJlYWQgYG51ZXZvVGhyZWFkYC4uLiIpOwogICAgICAgICAgICAgICAgICAgIC8vIENpY2xvIGluZmluaXRvLi4uCiAgICAgICAgICAgICAgICAgICAgLy8gU2Vyw6EgaW50ZXJydW1waWRvIHBvciBudWV2b1RocmVhZC5BYm9ydCgpIGVuIAogICAgICAgICAgICAgICAgICAgIC8vIGVsIHRocmVhZCBNYWluOgogICAgICAgICAgICAgICAgICAgIHdoaWxlKHRydWUpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICApOwogICAgICAgICAgICAKICAgICAgICAgICAgbnVldm9UaHJlYWQuU3RhcnQoKTsKICAgICAgICAgICAgCiAgICAgICAgICAgIC8vIFBlcm1pdGUgcXVlIGVsIHRocmVhZCBudWV2b1RocmVhZCBzZSBlamVjdXRlIAogICAgICAgICAgICAvLyBkdXJhbnRlIDIgc2VndW5kb3M6CiAgICAgICAgICAgIFRocmVhZC5TbGVlcCAoMjAwMCk7CiAgICAgICAgICAgIAogICAgICAgICAgICAvLyBBYm9ydGEgbGEgZWplY3VjacOzbiBkZWwgdGhyZWFkOgogICAgICAgICAgICBudWV2b1RocmVhZC5BYm9ydCgpOwogICAgICAgICAgICAKICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUgKCk7CiAgICAgICAgfQogICAgfQp9