Пример #1
0
        public AppDotTicker(int delayInterval)
        {
            DelayMillisec = delayInterval;

            new Thread(() =>
            {
                lock (typeof(T))
                {
                    while (true)
                    {
                        if (_shutdown)
                        {
                            OnCompletionEvent?.Invoke();
                            break;
                        }

                        if (_halt)
                        {
                            continue;
                        }

                        Thread.Sleep(DelayMillisec);
                        OnTickEvent?.Invoke();
                    }

                    IsActive = false;
                }
            })
            {
                IsBackground = true
            }
            .Start();
        }
Пример #2
0
        protected async void DoTimeout(float duration, Action <BaseTimer> cb = null)
        {
            runtime      = Time.time;
            currentDelay = duration;
            isRunning    = true;
            cts          = new CancellationTokenSource();

            while (!cts.IsCancellationRequested)
            {
                if (!isPaused)
                {
                    if (GetTimeSinceStart() >= currentDelay)
                    {
                        StopTimer();
                    }

                    MainDispatcher.Instance.Invoke(() =>
                    {
                        OnTickEvent?.Invoke(GetTimeLeft());
                    });

                    await Task.Delay(5);
                }
                else if (!cts.IsCancellationRequested && isPaused)
                {
                    await Task.Delay(5);
                }
                else if (!cts.IsCancellationRequested && isPaused)
                {
                    StopTimer();
                }
            }

            isRunning = false;
            if (!isUnloaded)
            {
                MainDispatcher.Instance.Invoke(() =>
                {
                    cb?.Invoke(this);
                });

                if (loop)
                {
                    loopCounter++;
                    if (LoopCounter < loopCount || loopCount.Equals(0))
                    {
                        SetTimeout(duration, cb);
                    }
                }
                else
                {
                    Unload();
                }
            }
        }
Пример #3
0
        private void Tick(object stateInfo)
        {
            AutoResetEvent autoEvent = (AutoResetEvent)stateInfo;

            OnTickEvent?.Invoke(--ctime);
            if (this.ctime == 0)
            {
                Done();
                autoEvent.Set();
            }
        }
Пример #4
0
        internal virtual void Update(GameTime gameTime)
        {
            Timer += (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (Timer > Interval)
            {
                var args = new OnTickEventArgs();
                OnTickEvent?.Invoke(this, args);
                Timer = 0;
            }
        }
Пример #5
0
 private void OnTick(object sender, object e)
 {
     _currentTime += _tickInterval;
     if (_currentTime >= _timelapse + _tickInterval)
     {
         OnEnd();
     }
     else if (Math.Abs(_currentTime - _timelapse) == _lowLimmit)
     {
         OnLowTimeLeft?.Invoke();
     }
     OnTickEvent?.Invoke(this.Timelapse, this.CurrentTime);
 }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private IEnumerator StartTicker()
        {
            CurrentTick = 0;

            while (true)
            {
                yield return(new WaitForSecondsRealtime(1));

                CurrentTick++;

                try
                {
                    OnTickEvent?.Invoke(CurrentTick);
                }
                catch (Exception e)
                {
                    Logs.Error(e);
                }
            }
        }