If you use Windows Phone, you are probably using Silverlight, not .NET 4.5, and this explains why your Stopwatch
class does not have a Restart
method.
In Silverlight Stopwatch.Start()
will start or resume measuring elapsed time for an interval.
The logic in the Start
, Stop
, Pause
and Resume
methods looks fine (*), but you only have event handlers for Button_Start
, Button_Stop
and Button_Pause
. No Button_Resume
.
Do you have a resume button? If not, where do you expect the Resume
method to be called from? Perhaps you connected the resume button to the Button_Start
handler, which will reset your stopwatch?
If you don't have a Resume button, and you want the Start button to resume after a pause and restart after a stop, simply change the Start button to the Only button to call Resume()
instead of Start()
.
private void Button_Start(object sender, RoutedEventArgs e) { Resume(); }
(*) However, you can turn off Stop / Pause when the stopwatch is not working, since you can click the Stop button, then pause, and then when you press the Start button, the timer will resume rather than restart, etc.
source share