Beispiel #1
0
        protected virtual void OnTimerTick(TimerEventArgs e)
        {
            // Make a temporary copy of the event to avoid possibility of
            // a race condition if the last subscriber unsubscribes
            // immediately after the null check and before the event is raised.
            TimerTickEventHandler handler = TimerTick;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Beispiel #2
0
        public async Task StartAsync(int numSeconds)
        {
            _isRunning = true;

            while (numSeconds >= 0 && _isRunning)
            {
                TimerTickEventHandler?.Invoke(this, new TimerEventArgs(numSeconds));

                await Task.Delay(1000); // one second tick

                --numSeconds;
            }
        }