Created
August 14, 2014 00:18
-
-
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.
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.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