Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created June 27, 2014 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/8764d9217dfbb0f28b54 to your computer and use it in GitHub Desktop.
Save Fhernd/8764d9217dfbb0f28b54 to your computer and use it in GitHub Desktop.
Demostración 'inmortalidad' de un thread ante múltiples intentos de abortar su ejecución.
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...");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment