예제 #1
0
        private async void ProgressTickHandlerAsync()
        {
            if (Value >= Max)
            {
                Progress = 100;
                return;
            }

            Timer.Change(Interval, Interval);

            Value = (DateTime.UtcNow - StartDate);

            Progress = (100 * Value.TotalMilliseconds) / Max.TotalMilliseconds;
            if (Progress >= 100)
            {
                Progress = 100;
            }

            if (Value >= Max)
            {
                Value    = Max;
                Progress = 100;
            }

            await ValueChanged.InvokeAsync(Value);

            if (Value == Max)
            {
                await OnElapsed.InvokeAsync(new BulTimeElapsedEventArgs(Max, Interval));
            }
        }
예제 #2
0
        public void Update(double timeSpeedMultiply = 1)
        {
            if (_running == false)
            {
                return;
            }

            IntervalLeft -= GeneralOptions.GameTime.ElapsedGameTime.Milliseconds * timeSpeedMultiply;

            if (IntervalLeft > 0)
            {
                return;
            }

            if (_runningToEnd)
            {
                return;
            }

            OnElapsed?.Invoke(this, null);

            if (IsRepeater)
            {
                IntervalLeft = IntervalMax;
            }
            else
            {
                Stop();
            }
        }
예제 #3
0
 private void NotifyTimerElapsed(Object source, ElapsedEventArgs e)
 {
     if (LoadingState == LoadingComponentState.Show)
     {
         Timer = Timer.AddMilliseconds(10);
     }
     OnElapsed?.Invoke(Timer);
 }
예제 #4
0
 private void NotifyTimerElapsed(object source, ElapsedEventArgs e)
 {
     OnElapsed?.Invoke();
     if (!_timer.AutoReset)
     {
         _timer.Stop();
         _timer.Dispose();
         _timer = null;
     }
 }
예제 #5
0
 public Debouncer(OnElapsed onElapsed, T initialValue, int milliseconds = 200)
 {
     Value      = initialValue;
     _debouncer = new Timer(milliseconds);
     _debouncer.Stop();
     _debouncer.AutoReset = false;
     _debouncer.Elapsed  += (_, __) =>
     {
         lock (_valueLock)
         {
             onElapsed.Invoke(Value);
         }
     };
 }
예제 #6
0
        private void DoTimer()
        {
            try
            {
                int last = Environment.TickCount;
                while (_IsStart)
                {
                    if (Environment.TickCount - last > _Interval)
                    {
                        OnElapsed?.Invoke();

                        last = Environment.TickCount;
                    }
                    Thread.Sleep(100);
                }
            }
            catch (Exception e)
            {
                log.Error("定时DoTimer()出错:" + e.Message.ToString());
            }
        }
예제 #7
0
 private void onCoreTimerTick(object sender, EventArgs e)
 {
     if (elapsed < time)
     {
         elapsed += interval;
         double ratio = (double)elapsed / time;
         OnTick?.Invoke(ratio);
     }
     else
     {
         OnElapsed?.Invoke();
         if (isRepeating)
         {
             elapsed = 0;
         }
         else
         {
             coreTimer.Stop();
             isRunning = false;
         }
     }
 }
예제 #8
0
 private void SetupTimer(double interval, int playCount, Action <int> intervalAction, bool dispose)
 {
     if (!IsValidTimeInterval(interval) ||
         intervalAction == null ||
         playCount <= 0)
     {
         return;
     }
     timer.Interval  = interval;
     this.playCount  = playCount;
     counter         = 0;
     timer.AutoReset = playCount != 1;
     timer.Elapsed  += (object sender, ElapsedEventArgs e) =>
     {
         counter++;
         intervalAction(counter);
         OnElapsed?.Invoke(counter);
         if (counter >= playCount && playCount > 0)
         {
             StopTimer(dispose);
         }
     };
 }
예제 #9
0
 private void NotifyTimerElapsed(Object source, ElapsedEventArgs e)
 {
     OnElapsed?.Invoke();
     _timer.Dispose();
 }
예제 #10
0
 private void NotifyTimerElapsed(object source, ElapsedEventArgs e)
 {
     OnElapsed?.Invoke();
 }
 public void OperationScheduleElapsed()
 {
     OnElapsed?.Invoke();
 }
 private void NotifyTimerElapsed(Object source, System.Timers.ElapsedEventArgs e)
 {
     OnElapsed?.Invoke();
 }