Search This Blog

Wednesday, November 6, 2013

Stopwatch C# Example

C# > Diagnostics > Stopwatch 

Stopwatch measures elapsed time.

The Stopwatch measures elapsed time by counting timer ticks in the timer mechanism. If the installed hardware and operating system support a high-resolution performance counter, then the Stopwatch class uses that counter to measure elapsed time.

Example:


Stopwatch sw = new Stopwatch();
sw.Start();
Thread.Sleep(500);
sw.Stop();
TimeSpan ts = sw.Elapsed;
MessageBox.Show("Elapsed time " + ts.ToString());