Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created June 27, 2014 03:56
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/bfa4c74da70c8ba665fe to your computer and use it in GitHub Desktop.
Save Fhernd/bfa4c74da70c8ba665fe to your computer and use it in GitHub Desktop.
Demostración de los estados de un thread antes y después de ser abortado.
using System;
using System.Threading;
namespace Recetas.Threading.Cap01
{
public sealed class VerificacionEstadoThread
{
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);
}
);
// El thread nuevoThread aún no se ha iniciado:
Console.WriteLine ("\n1 - Estado actual de `nuevoThread`: {0}", nuevoThread.ThreadState);
// Inicio del thread `nuevoThread`:
nuevoThread.Start();
Thread.Sleep (1000);
// `nuevoThread` se haya en ejecución:
Console.WriteLine ("\n2 - Estado actual de `nuevoThread`: {0}", nuevoThread.ThreadState);
// Aborta la ejecución de `nuevoThread`:
nuevoThread.Abort();
// Nuevo estado de `nuevoThread`:
Console.WriteLine ("\n3 - Estado actual de `nuevoThread`: {0}", nuevoThread.ThreadState);
// Intento de poner en espera el thread Main,
// sin embargo el `nuevoThread` ha sido abortado:
nuevoThread.Join ();
Console.WriteLine ("\n4 - Estado actual de `nuevoThread`: {0}\n", nuevoThread.ThreadState);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment