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 ( "\n Presione 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..." ) ;
}
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGhyZWFkaW5nOwoKbmFtZXNwYWNlIFJlY2V0YXMuQ1NoYXJwLkNhcDA0LlIwNDEyCnsKICAgIHB1YmxpYyBzZWFsZWQgY2xhc3MgVXNvSm9pbgogICAgewogICAgICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKICAgICAgICB7CiAgICAgICAgICAgIC8vIENyZWFjacOzbiBUaHJlYWQ6CiAgICAgICAgICAgIFRocmVhZCB0ID0gbmV3IFRocmVhZChUYXJlYSk7CiAgICAgICAgICAgIAogICAgICAgICAgICAvLyBJbmljaW8gZGUgbGEgZWplY3VjacOzbjoKICAgICAgICAgICAgdC5TdGFydCgpOwogICAgICAgICAgICAKICAgICAgICAgICAgLy8gSW52b2NhIGEgSm9pbiB5IGVzcGVyYSBhIHF1ZSBmaW5hbGljZToKICAgICAgICAgICAgdC5Kb2luKCk7CiAgICAgICAgICAgIAogICAgICAgICAgICAvLyBFc3RhcyBsw61uZWFzIHNlIGVqZWN1dGFyw6FuIGFwZW5hcyBlc3RlIHRocmVhZCBzZSAKICAgICAgICAgICAgLy8gZGVzYmxvcXVlLCBlcyBkZWNpciwgaGFzdGEgcXVlIGxhIGxsYW1hZGEgYSBKb2luIAogICAgICAgICAgICAvLyBoYXlhIGZpbmFsaXphZG86CiAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lICgiXG5QcmVzaW9uZSBFbnRlciBwYXJhIGZpbmFsaXphci5cbiIpOwogICAgICAgICAgICBDb25zb2xlLlJlYWRMaW5lICgpOwogICAgICAgIH0KICAgICAgICAKICAgICAgICAvLyBFamVjdWNpw7NuIHNvYnJlIHVuIG51ZXZvIHRocmVhZDoKICAgICAgICBwcml2YXRlIHN0YXRpYyB2b2lkIFRhcmVhKCkKICAgICAgICB7CiAgICAgICAgICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IDU7ICsraSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgVGhyZWFkLlNsZWVwKDEwMDApOwogICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUgKCJVbiBzZWd1bmRvIGhhIHRyYW5zY3Vycmlkby4uLiIpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQp9