using System;
using System.Threading;
namespace Recetas.Multithreading.Cap01
{
internal class UsoThreadJoinTimeSpan
{
// Instancia TimeSpan que representa un
// intervalo de tiempo de 2 segundos
private static TimeSpan tiempoEspera = new TimeSpan (0, 0, 1);
public static void Main()
{
// Creación de instancia de Thread para
// encapsular el método Tarea:
Thread nuevoThread = new Thread (Tarea);
nuevoThread.Start();
// Espera durante dos segundos:
if (nuevoThread.Join (tiempoEspera + tiempoEspera))
{
Console.WriteLine ("\n`nuevoThread` ha terminado.");
}
else
{
Console.WriteLine ("\nEl tiempo de espera ha caducado.");
}
}
private static void Tarea()
{
Thread.Sleep (tiempoEspera);
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uVGhyZWFkaW5nOwoKbmFtZXNwYWNlIFJlY2V0YXMuTXVsdGl0aHJlYWRpbmcuQ2FwMDEKewogICAgaW50ZXJuYWwgY2xhc3MgVXNvVGhyZWFkSm9pblRpbWVTcGFuCiAgICB7CiAgICAgICAgLy8gSW5zdGFuY2lhIFRpbWVTcGFuIHF1ZSByZXByZXNlbnRhIHVuIAogICAgICAgIC8vIGludGVydmFsbyBkZSB0aWVtcG8gZGUgMiBzZWd1bmRvcwogICAgICAgIHByaXZhdGUgc3RhdGljIFRpbWVTcGFuIHRpZW1wb0VzcGVyYSA9IG5ldyBUaW1lU3BhbiAoMCwgMCwgMSk7CiAgICAgICAgCiAgICAgICAgcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQogICAgICAgIHsKICAgICAgICAgICAgLy8gQ3JlYWNpw7NuIGRlIGluc3RhbmNpYSBkZSBUaHJlYWQgcGFyYSAKICAgICAgICAgICAgLy8gZW5jYXBzdWxhciBlbCBtw6l0b2RvIFRhcmVhOgogICAgICAgICAgICBUaHJlYWQgbnVldm9UaHJlYWQgPSBuZXcgVGhyZWFkIChUYXJlYSk7CiAgICAgICAgICAgIG51ZXZvVGhyZWFkLlN0YXJ0KCk7CiAgICAgICAgICAgIAogICAgICAgICAgICAvLyBFc3BlcmEgZHVyYW50ZSBkb3Mgc2VndW5kb3M6CiAgICAgICAgICAgIGlmIChudWV2b1RocmVhZC5Kb2luICh0aWVtcG9Fc3BlcmEgKyB0aWVtcG9Fc3BlcmEpKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSAoIlxuYG51ZXZvVGhyZWFkYCBoYSB0ZXJtaW5hZG8uIik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSAoIlxuRWwgdGllbXBvIGRlIGVzcGVyYSBoYSBjYWR1Y2Fkby4iKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAKICAgICAgICBwcml2YXRlIHN0YXRpYyB2b2lkIFRhcmVhKCkKICAgICAgICB7CiAgICAgICAgICAgIFRocmVhZC5TbGVlcCAodGllbXBvRXNwZXJhKTsKICAgICAgICB9CiAgICB9Cn0=