A class in the System. Diagnostics namespace.
In fact, it is equivalent to a stopwatch. It can be stopped more than once. The Start method is to press the stopwatch to Start timing. The Stop method is to press the stopwatch again to pause timing. The IsRunning attribute is used to determine whether the stopwatch is running. The Reset method is to clear the stopwatch.
Its mechanism is as follows:
If the installed hardware or operating system provides a high-resolution counter, use that counter; otherwise, the system timer. Frequency and IsHighResolution are used to determine the accuracy and whether the resolution is high.
TIPS:
Which of the following cores does not affect the processing of multi-core computers?
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Diagnostics;
Using System. Threading;
Namespace _ 090914_ApplicationRunSpan1
{
Class Program
{
Static void Main (string [] args)
{
Stopwatch watcher = new Stopwatch ();
Watcher. Start ();
Thread. Sleep (2500 );
If (watcher. IsRunning)
Console. WriteLine ("The watcher is running .");
Watcher. Stop ();
Console. WriteLine (watcher. ElapsedMilliseconds. ToString () + "Milliseconds ");
TimeSpan ts = watcher. Elapsed;
Console. WriteLine (String. Format ("{0: 00 }",
Ts. Hours, ts. Minutes, ts. Seconds,
Ts. Milliseconds/10 ));
Console. Read ();
}
}
}
When watcher. IsRunning was not added to the program above, Sleep also experienced 2500 ms. However, it seems that only Sleep is 2499, which is also random.