예제 #1
0
        /// <summary>
        /// Уменьшить время (счетчик)
        /// </summary>
        /// <param name="milliseconds"></param>
        public void CountDown(int milliseconds = 1000)
        {
            //Усеньшить счетчик
            if (this.State == PomodoroState.Working ||
                this.State == PomodoroState.Relaxing)
            {
                this.CountdownTime -= milliseconds;
            }
            else
            {
                //Если статус другой, то не можем трогать счетчик
                return;
            }

            //Если счетчик <=0, то поменять статус и обновить счетчик.
            if (this.CountdownTime < 0)
            {
                OnTimeFinish?.Invoke(this);
                switch (this.State)
                {
                case PomodoroState.Relaxing:
                    this.State         = PomodoroState.WorkStopping;
                    this.CountdownTime = _timeForWork;
                    break;

                case PomodoroState.Working:
                    this.State         = PomodoroState.RelaxStopping;
                    this.CountdownTime = _timeForRelax;
                    break;
                }
            }
        }
예제 #2
0
 public void ClockTick(object obj)
 {
     lock (ClockTickMonitor)
     {
         if (LastTurnStartAt.HasValue)
         {
             SpentTime = DateTime.UtcNow.Subtract(LastTurnStartAt.Value);
             LeftTime  = TotalTime - SpentTime;
             if (LeftTime.TotalSeconds <= 0)
             {
                 Stop();
                 this.State = ClockState.Finished;
                 OnTimeFinish?.Invoke(this, new ChessClockEventArgs(Player)); //WARNING: Event Raised in a background thread.
             }
         }
     }
 }