Created
July 22, 2015 13:35
-
-
Save Fhernd/08b67b8c3c26c08c1a81 to your computer and use it in GitHub Desktop.
Uso de la clase Stopwatch 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
// 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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment