예제 #1
0
 public void Pause()
 {
     if (this.State == TDTimerState.Running)
     {
         this.State = TDTimerState.Paused;
     }
 }
예제 #2
0
 void TDTimer_Elapsed(object sender, ElapsedEventArgs e)
 {
     // the timer was running, and the duration elapsed.
     if (this.State == TDTimerState.Running)
     {
         this.State = TDTimerState.Finished;
     }
 }
예제 #3
0
        private void HandleStateChange(TDTimerState oldState, TDTimerState newState)
        {
            // if same state, ignore
            if (oldState == newState)
            {
                return;
            }

            if (oldState == TDTimerState.Finished)
            {
                return;
            }                                                  // never switch away from finished.

            // otherwise do something based on the new state
            switch (newState)
            {
            case TDTimerState.Finished:
                // timer has finished
                break;

            case TDTimerState.Paused:
                // user has paused the game, so pause this timer
                PauseWhen = DateTime.Now;
                //base.Enabled = false;
                break;

            case TDTimerState.Running:
                if (oldState == TDTimerState.NotStartedYet)
                {
                    // starting for first time
                }
                else if (oldState == TDTimerState.Paused)
                {
                    // set the remaining duration because the timer starts over
                    this.Duration = new TimeSpan(0, 0, 0, 0, (int)Math.Max(0, DurationRemaining.TotalMilliseconds));
                }

                // and set the resumeWhen time for future state changes
                ResumeWhen = DateTime.Now;

                break;

            case TDTimerState.NotStartedYet:     // should never get here
            default:
                break;
            }
        }
예제 #4
0
        public void Resume()
        {
            if (this.State == TDTimerState.NotStartedYet)
            {
                base.Start();
                if (ResumeWhen == new DateTime())
                {
                    ResumeWhen = DateTime.Now;
                }

                this.State = TDTimerState.Running;
            }
            else if (this.State == TDTimerState.Paused)
            {
                this.State = TDTimerState.Running;
            }
            this.ChangeSpeedWhen = DateTime.Now;
        }