Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // OrtizOL - xCSw - http://ortizol.blogspot.com
  2.  
  3. using System;
  4. using System.Diagnostics;
  5. using System.Threading;
  6.  
  7. namespace Receta.CSharp.R0303
  8. {
  9.     public class UsoStopwatch
  10.     {
  11.         public static void Main()
  12.         {
  13.             Console.WriteLine(Environment.NewLine);
  14.            
  15.             Stopwatch sw = new Stopwatch();
  16.            
  17.             // Inicia el cronómetro:
  18.             sw.Start();
  19.            
  20.             // Simula la ejecución durante 10':
  21.             Thread.Sleep(10000);
  22.            
  23.             // Detiene el cronómetro:
  24.             sw.Stop();
  25.            
  26.             // Obtiene el tiempo transcurrido:
  27.             TimeSpan ts = sw.Elapsed;
  28.            
  29.             // Formato de la representación del tiempo
  30.             // transcurrido:
  31.             string formatoTiempo = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
  32.                                     ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
  33.                                    
  34.             Console.WriteLine("Tiempo cronometrizado: {0}", formatoTiempo);
  35.            
  36.             Console.WriteLine(Environment.NewLine);
  37.         }
  38.     }
  39. }