Created
June 19, 2014 02:24
-
-
Save Fhernd/47f248cca3844468267f to your computer and use it in GitHub Desktop.
Demostración de la precisión del método Sleep. 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.Diagnostics; | |
using System.Threading; | |
namespace Recetas.Multithreading.Cap01 | |
{ | |
public sealed class PrecisionThreadSleep | |
{ | |
public static void Main() | |
{ | |
// Empieza cronometrar el tiempo transcurrido a partir | |
// del inicio del Thread asociado con Main: | |
Stopwatch sw = Stopwatch.StartNew(); | |
// Pausa el Thread 0 segundos: | |
Thread.Sleep (0); | |
// Detiene el crónometro: | |
sw.Stop(); | |
Console.WriteLine (sw.ElapsedMilliseconds); | |
Console.WriteLine (DateTime.Now.ToLongTimeString()); | |
// Inicia de nuevo el cronómetro: | |
sw = Stopwatch.StartNew(); | |
// Detiene el Thread por 5000 ms (5s): | |
Thread.Sleep (5000); | |
sw.Stop(); | |
Console.WriteLine (sw.ElapsedMilliseconds); | |
Console.WriteLine (DateTime.Now.ToLongTimeString()); | |
// Una vez más iniciamos el cronómetro: | |
sw = Stopwatch.StartNew(); | |
Thread.Sleep(1000); | |
sw.Stop(); | |
Console.WriteLine (sw.ElapsedMilliseconds); | |
Console.WriteLine (DateTime.Now.ToLongTimeString()); | |
Console.WriteLine (); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment