Example #1
0
        private void OnTimerCallback(object state)
        {
            var info          = _userStateService.GetUserState();
            var previousState = CurrentTimeWarpState;

            CurrentTimeWarpState = info.State;
            MinutesRemaining     = info.TimeLeft.Minutes;

            if (info.State == TimeWarpState.Resting && previousState == TimeWarpState.Working)
            {
                OnUserStateChanged(UserMessage.TakeABreak);
            }

            if (info.State == TimeWarpState.None && previousState == TimeWarpState.Resting)
            {
                OnUserStateChanged(UserMessage.TimeToWork);
            }

            if (info.State == TimeWarpState.Working && previousState != TimeWarpState.Working)
            {
                OnUserStateChanged(UserMessage.Working);
            }

            OnTimeChanged(MinutesRemaining);
            _timer.Change(RefreshPeriod, TimeSpan.Zero);
        }
        private void OnTimerCallback(object state)
        {
            var info = _userStateService.GetUserState();//in try catch?

            if (info != null)
            {
                var previousState = CurrentTimeWarpState;

                CurrentTimeWarpState = info.State;
                MinutesRemaining     = info.TimeLeft.Minutes;

                if (info.State == TimeWarpState.Resting && previousState == TimeWarpState.Working)
                {
                    OnUserStateChanged(UserMessage.TakeABreak, info.TimeWarpAgent);
                }

                if (info.State == TimeWarpState.None && previousState == TimeWarpState.Resting)
                {
                    OnUserStateChanged(UserMessage.TimeToWork, info.TimeWarpAgent);
                }

                if (info.State == TimeWarpState.Working && previousState != TimeWarpState.Working)
                {
                    OnUserStateChanged(UserMessage.Working, info.TimeWarpAgent);
                }

                OnTimeChanged(MinutesRemaining);
            }

            lock (_disposeTimer)
            {
                if (_timer != null)
                {
                    _timer.Change(RefreshPeriod, TimeSpan.Zero); //todo fix dispose
                }
            }
        }