Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created June 27, 2014 03:45
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/4fd0da67d24210e1174e to your computer and use it in GitHub Desktop.
Save Fhernd/4fd0da67d24210e1174e to your computer and use it in GitHub Desktop.
Demostración de uso del método Thread.Abort() para abortar un thread en ejecución.
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 ();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment