Created
June 27, 2014 03:45
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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