Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created June 27, 2014 03:23
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/41cd68cd8601da8d5817 to your computer and use it in GitHub Desktop.
Save Fhernd/41cd68cd8601da8d5817 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.Threading.Cap01
{
internal sealed class UsoBasicoThreadAbort
{
public static void Main()
{
Thread threadNuevo = new Thread (MostrarMensaje);
if (threadNuevo.IsAlive)
{
// Inicia la ejecución del nuevo thread:
threadNuevo.Start();
// Detiene el thread:
threadNuevo.Abort();
}
// Código ejecutado en el thread Main:
for (int i = 0; i < 10; ++i)
{
Console.WriteLine ("OrtizOL - xCSw");
}
Console.WriteLine ("\nEl thread Main ha terminado.\n");
}
private static void MostrarMensaje ()
{
for (int i = 0; i < 10; ++i)
{
Console.WriteLine ("Recetas Multithreading en C#");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment