Beispiel #1
0
    public void StartTimer(float duration)
    {
        _timerRoutine = StartCoroutine(TimerRoutine());
        IEnumerator TimerRoutine()
        {
            _scd = new SpecialCountDown(duration);
            while (!_scd.isDone)
            {
                int seconds = (int)_scd.RemainingTime;
                if (seconds >= 60)
                {
                    _text.text = $"{(seconds/60<0?"0": string.Empty)}{seconds/60} : {(seconds % 60 < 10 ? "0" : string.Empty)}{seconds % 60}";
                }
                else if (seconds >= 10)
                {
                    _text.text = $"{seconds % 60}";
                }
                else
                {
                    _text.text = $"0{seconds % 60}";
                }
                yield return(null);
            }

            OnTimeOut?.Invoke();
            yield break;
        }
    }
Beispiel #2
0
        /// <summary>
        /// 构造会话管理器
        /// </summary>
        /// <param name="context"></param>
        /// <param name="bufferSize"></param>
        /// <param name="count"></param>
        /// <param name="completed"></param>
        public SessionManager(IContext context, int bufferSize, int count, EventHandler <SocketAsyncEventArgs> completed, TimeSpan timeOut)
        {
            _userTokenPool = new UserTokenPool(context, count);

            _session    = new OuterMemoryCacheHelper <IUserToken>();
            _timeOut    = timeOut;
            _bufferSize = bufferSize;
            _completed  = completed;

            _bufferManager = new BufferManager(bufferSize * count, bufferSize);
            _bufferManager.InitBuffer();

            _argsPool = new SocketAsyncEventArgsPool(count * 2);
            _argsPool.InitPool(_completed);

            //超时处理 timeout handler
            ThreadHelper.PulseAction(() =>
            {
                var values = _session.List.Where(b => b.Expired < DateTimeHelper.Now);
                if (values != null)
                {
                    foreach (var val in values)
                    {
                        if (val != null)
                        {
                            OnTimeOut?.Invoke(val.Value);
                        }
                    }
                }
            }, new TimeSpan(0, 0, 10), false);
        }
Beispiel #3
0
 private void _session_OnChanged(bool isAdd, IUserToken userToken)
 {
     if (!isAdd)
     {
         OnTimeOut?.Invoke(userToken);
     }
 }
Beispiel #4
0
 private void _sessionCache_OnChanged(MemoryCache <IUserToken> obj, bool isAdd, IUserToken userToken)
 {
     if (!isAdd)
     {
         OnTimeOut?.Invoke(userToken);
     }
 }
Beispiel #5
0
 internal static void NewTimeOut(string id)
 {
     if (OnTimeOut != null)
     {
         OnTimeOut.Invoke(id);
     }
 }
Beispiel #6
0
    ///<summary>
    ///Handles time flow. Starts the event when timer reaches 0.
    ///</summary>
    public void FixedUpdate()
    {
        currentTime -= Time.fixedDeltaTime;

        if (currentTime <= 0 && !timedOut)
        {
            timedOut = true;
            OnTimeOut?.Invoke();
        }
    }
Beispiel #7
0
        private void Tick(object sender, ElapsedEventArgs e)
        {
            Percentage++;


            if (Percentage == 100)
            {
                m_timer.Stop();
                TextTime = "Temps écoulé";
                OnTimeOut?.Invoke();
                Visible = Visibility.Hidden;
            }
        }
        public async void Poll()
        {
            if (await GetPingTime() > 2000)
            {
                OnTimeOut?.Invoke();
            }

            while (messageInQueue.Count > 0)
            {
                Message m;
                if (messageInQueue.TryDequeue(out m))
                {
                    OnPoll(m);
                }
            }
        }
 void CDNow()
 {
     if (m_timer < CDTime)
     {
         m_cd     = m_timer / CDTime;
         m_timer += UnityEngine.Time.deltaTime;
     }
     else
     {
         m_cd = 1.0f;
         Stop();
         if (OnTimeOut != null)
         {
             OnTimeOut.Invoke();
         }
     }
 }
Beispiel #10
0
    private void Update()
    {
        if (_isTimeOut || _isPaused)
        {
            return;
        }

        _currentTime = Mathf.Max(0, _currentTime - Time.deltaTime);

        if (_currentTime > 0)
        {
            UpdateUI(_currentTime);
        }
        else
        {
            _isTimeOut = true;
            OnTimeOut?.Invoke();
        }
    }
Beispiel #11
0
        public void Start()
        {
            if (Time > 0.0)
            {
                m_timer = new System.Timers.Timer()
                {
                    Interval = Time * 10
                };

                m_timer.Elapsed += Tick;
                m_timer.Start();

                Visible = Visibility.Visible;
            }
            else
            {
                OnTimeOut?.Invoke();
            }
        }
Beispiel #12
0
 private void Finish()
 {
     OnTimeOut?.Invoke();
 }