Stopwatch provides several methods to control the stopwatch object. The start method starts a timing operation, and the Stop method stops timing. If the start method is used for the second time, the timing continues, and the final result is the accumulation of the two times. To avoid this, use the reset method to zero the object before the second timer. No parameters are required for these three methods.
Namespace: system. Diagnostics
Constructor: stopwatch Sw = new stopwatch ();
Method:
Start starts or continues to measure the running time at a certain interval.
Stop stops measuring the running time at a certain interval.
Reset reset timer.
Elapsed obtains the total running time measured by the current instance.
Usage:
Using system. diagnostics;
Stopwatch Sw = new stopwatch ();
Sw. Start ();
// The program code for timing is here
Sw. Stop ();
Double time = Sw. elapsed. totalmilliseconds;
MessageBox. Show ("program time:" + time );