Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using System;
  2. using System.Diagnostics;
  3. using System.Threading;
  4.  
  5. namespace Recetas.Multithreading.Cap01
  6. {
  7.     public sealed class PrecisionThreadSleep
  8.     {
  9.         public static void Main()
  10.         {
  11.             // Empieza cronometrar el tiempo transcurrido a partir
  12.             // del inicio del Thread asociado con Main:
  13.             Stopwatch sw = Stopwatch.StartNew();
  14.             // Pausa el Thread 0 segundos:
  15.             Thread.Sleep (0);
  16.             // Detiene el crónometro:
  17.             sw.Stop();
  18.             Console.WriteLine (sw.ElapsedMilliseconds);
  19.             Console.WriteLine (DateTime.Now.ToLongTimeString());
  20.            
  21.             // Inicia de nuevo el cronómetro:
  22.             sw = Stopwatch.StartNew();
  23.             // Detiene el Thread por 5000 ms (5s):
  24.             Thread.Sleep (5000);
  25.             sw.Stop();
  26.             Console.WriteLine (sw.ElapsedMilliseconds);
  27.             Console.WriteLine (DateTime.Now.ToLongTimeString());
  28.            
  29.             // Una vez más iniciamos el cronómetro:
  30.             sw = Stopwatch.StartNew();
  31.             Thread.Sleep(1000);
  32.             sw.Stop();
  33.             Console.WriteLine (sw.ElapsedMilliseconds);
  34.             Console.WriteLine (DateTime.Now.ToLongTimeString());
  35.            
  36.             Console.WriteLine ();
  37.         }
  38.     }
  39. }