/// <summary> /// stopwatch button /// </summary> private void ActionLikeProdigy() { switch (State) { case StopwatchState.None: _sw.Start(); State = StopwatchState.Recording; _dtTimer.Start(); xTipStart.Content = string.Format(XTIP_START_CONTENT, "Stop"); xTip.Content = string.Format(XTIP_CONTENT, "stop"); break; case StopwatchState.Recording: _sw.Stop(); State = StopwatchState.Stopped; xTipStart.Content = string.Format(XTIP_START_CONTENT, "Restart"); xTip.Content = string.Format(XTIP_CONTENT, "restart"); break; case StopwatchState.Stopped: _sw.Restart(); State = StopwatchState.Recording; xTipStart.Content = string.Format(XTIP_START_CONTENT, "Stop"); xTip.Content = string.Format(XTIP_CONTENT, "stop"); break; } }
public void changeState() { if (state == StopwatchState.Pause) { lastStopTimeSpan = new TimeSpan(0); startDateTime = DateTime.UtcNow; state = StopwatchState.Zero; } else if (state == StopwatchState.Play) { TimeSpan ts = DateTime.UtcNow - startDateTime; lastStopTimeSpan = ts + lastStopTimeSpan; state = StopwatchState.Pause; } else { startDateTime = DateTime.UtcNow; state = StopwatchState.Play; } }