using System;
using System.Threading;
namespace Recetas.Multithreading.Cap01
{
internal class InmortalidadThread
{
public static void Main()
{
Thread nuevoThread = new Thread(EjecutarTarea);
nuevoThread.Start();
// Intento no. 1 de abortar el thread nuevoThread:
Thread.Sleep (1000);
nuevoThread.Abort();
// Intento no. 2 de abortar el thread nuevoThread:
Thread.Sleep (1000);
nuevoThread.Abort();
// Intento no. 3 de abortar el thread nuevoThread:
Thread.Sleep (1000);
nuevoThread.Abort();
}
private static void EjecutarTarea()
{
while (true)
{
try
{
while (true);
}
catch (ThreadAbortException)
{
// Recuperación de la excepción
// ThreadAbortException:
Thread.ResetAbort();
}
Console.WriteLine ("El thread permanece activo...");
}
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGhyZWFkaW5nOwoKbmFtZXNwYWNlIFJlY2V0YXMuTXVsdGl0aHJlYWRpbmcuQ2FwMDEKewogICAgaW50ZXJuYWwgY2xhc3MgSW5tb3J0YWxpZGFkVGhyZWFkCiAgICB7CiAgICAgICAgcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQogICAgICAgIHsKICAgICAgICAgICAgVGhyZWFkIG51ZXZvVGhyZWFkID0gbmV3IFRocmVhZChFamVjdXRhclRhcmVhKTsKICAgICAgICAgICAgCiAgICAgICAgICAgIG51ZXZvVGhyZWFkLlN0YXJ0KCk7CiAgICAgICAgICAgIAogICAgICAgICAgICAvLyBJbnRlbnRvIG5vLiAxIGRlIGFib3J0YXIgZWwgdGhyZWFkIG51ZXZvVGhyZWFkOgogICAgICAgICAgICBUaHJlYWQuU2xlZXAgKDEwMDApOwogICAgICAgICAgICBudWV2b1RocmVhZC5BYm9ydCgpOwogICAgICAgICAgICAKICAgICAgICAgICAgLy8gSW50ZW50byBuby4gMiBkZSBhYm9ydGFyIGVsIHRocmVhZCBudWV2b1RocmVhZDoKICAgICAgICAgICAgVGhyZWFkLlNsZWVwICgxMDAwKTsKICAgICAgICAgICAgbnVldm9UaHJlYWQuQWJvcnQoKTsKICAgICAgICAgICAgCiAgICAgICAgICAgIC8vIEludGVudG8gbm8uIDMgZGUgYWJvcnRhciBlbCB0aHJlYWQgbnVldm9UaHJlYWQ6CiAgICAgICAgICAgIFRocmVhZC5TbGVlcCAoMTAwMCk7CiAgICAgICAgICAgIG51ZXZvVGhyZWFkLkFib3J0KCk7CiAgICAgICAgfQogICAgICAgIAogICAgICAgIHByaXZhdGUgc3RhdGljIHZvaWQgRWplY3V0YXJUYXJlYSgpCiAgICAgICAgewogICAgICAgICAgICB3aGlsZSAodHJ1ZSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgdHJ5CiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgd2hpbGUgKHRydWUpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgY2F0Y2ggKFRocmVhZEFib3J0RXhjZXB0aW9uKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIC8vIFJlY3VwZXJhY2nDs24gZGUgbGEgZXhjZXBjacOzbiAKICAgICAgICAgICAgICAgICAgICAvLyBUaHJlYWRBYm9ydEV4Y2VwdGlvbjoKICAgICAgICAgICAgICAgICAgICBUaHJlYWQuUmVzZXRBYm9ydCgpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSAoIkVsIHRocmVhZCBwZXJtYW5lY2UgYWN0aXZvLi4uIik7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9Cn0=