// OrtizOL - xCSw - http://ortizol.blogspot.com
using System;
using System.Diagnostics;
using System.Threading;
namespace Receta.CSharp.R0303
{
public class UsoStopwatch
{
public static void Main()
{
Console.WriteLine(Environment.NewLine);
Stopwatch sw = new Stopwatch();
// Inicia el cronómetro:
sw.Start();
// Simula la ejecución durante 10':
Thread.Sleep(10000);
// Detiene el cronómetro:
sw.Stop();
// Obtiene el tiempo transcurrido:
TimeSpan ts = sw.Elapsed;
// Formato de la representación del tiempo
// transcurrido:
string formatoTiempo = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
Console.WriteLine("Tiempo cronometrizado: {0}", formatoTiempo);
Console.WriteLine(Environment.NewLine);
}
}
}