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; } }
/// <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); }
private void _session_OnChanged(bool isAdd, IUserToken userToken) { if (!isAdd) { OnTimeOut?.Invoke(userToken); } }
private void _sessionCache_OnChanged(MemoryCache <IUserToken> obj, bool isAdd, IUserToken userToken) { if (!isAdd) { OnTimeOut?.Invoke(userToken); } }
internal static void NewTimeOut(string id) { if (OnTimeOut != null) { OnTimeOut.Invoke(id); } }
///<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(); } }
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(); } } }
private void Update() { if (_isTimeOut || _isPaused) { return; } _currentTime = Mathf.Max(0, _currentTime - Time.deltaTime); if (_currentTime > 0) { UpdateUI(_currentTime); } else { _isTimeOut = true; OnTimeOut?.Invoke(); } }
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(); } }
private void Finish() { OnTimeOut?.Invoke(); }