Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Last active August 29, 2015 14:03
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/aba743b6ef4983ee17c4 to your computer and use it in GitHub Desktop.
Save Fhernd/aba743b6ef4983ee17c4 to your computer and use it in GitHub Desktop.
Demostración del uso del método Thread.Join(TimeSpan) en C#.
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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment