Last active
August 29, 2015 14:03
-
-
Save Fhernd/aba743b6ef4983ee17c4 to your computer and use it in GitHub Desktop.
Demostración del uso del método Thread.Join(TimeSpan) en C#.
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.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