Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created August 14, 2014 00:18
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/7e4b37fa085529f91581 to your computer and use it in GitHub Desktop.
Save Fhernd/7e4b37fa085529f91581 to your computer and use it in GitHub Desktop.
Uso del método Thread.Join para determinar cuándo un thread ha finalizado su ejecución.
using System;
using System.Threading;
namespace Recetas.CSharp.Cap04.R0412
{
public sealed class UsoJoin
{
public static void Main()
{
// Creación Thread:
Thread t = new Thread(Tarea);
// Inicio de la ejecución:
t.Start();
// Invoca a Join y espera a que finalice:
t.Join();
// Estas líneas se ejecutarán apenas este thread se
// desbloque, es decir, hasta que la llamada a Join
// haya finalizado:
Console.WriteLine ("\nPresione Enter para finalizar.\n");
Console.ReadLine ();
}
// Ejecución sobre un nuevo thread:
private static void Tarea()
{
for (int i = 1; i <= 5; ++i)
{
Thread.Sleep(1000);
Console.WriteLine ("Un segundo ha transcurrido...");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment