To set the timer information to zero, use the Stopwatch Restart method.
Firstly, begin the Stopwatch −
Stopwatch s = Stopwatch.StartNew();
Then, use Restart() to set the timer to zero −
s.Restart();
Let us see the complete code −
Example
using System;
using System.Threading;
using System.Diagnostics;
public class Demo {
public static void Main() {
Stopwatch s = Stopwatch.StartNew();
Thread.Sleep(500);
// restart
s.Restart();
// begin again
Thread.Sleep(500);
Console.WriteLine(s.Elapsed);
}
}Output
00:00:00.5004937