- Stopwatch instance can measure a running time interval, or the sum of a plurality of measurement time interval used.
- Namespace System.Diagnostics.
Simple to use
. 1 the using the System; 2 the using the System.Diagnostics; . 3 namespace Demo . 4 { . 5 class Program . 6 { . 7 static void the Main ( String [] args) . 8 { . 9 var SW = Stopwatch.StartNew (); // create the object 10 . 11 SW. start (); // start the timer 12 13 iF (sw.IsRunning) // determine whether the timer clocking 14 Console.WriteLine ($ " timer is counting" ); 15 16 sw.Restart (); // After stopping cleared to restart timing. 17 18 sw.Reset (); // cleared and stop the clock 19 20 sw.Stop (); // end timing 21 22 Console.WriteLine ($ " program total time of: sw.ElapsedTicks {} " ); 23 is } 24 } 25 }