コード例 #1
0
        /// <summary>
        /// Rise event method
        /// </summary>
        public void SimulateCountdown()
        {
            TimerEventArgs e = new TimerEventArgs();

            while (_milliseconds >= 0)
            {
                Console.Clear();
                Console.WriteLine($"{_milliseconds / 1000} sec");
                Thread.Sleep(1000);
                _milliseconds -= 1000;
            }

            e.Time         = DateTime.Now;
            e.Milliseconds = _milliseconds;
            e.Message      = "Timer was stopped!!";
            OnTimer(e);
        }
コード例 #2
0
 protected virtual void OnTimer(TimerEventArgs e)
 {
     Volatile.Read(ref CountdownEvent)?.Invoke(this, e);
 }
コード例 #3
0
 /// <summary>
 /// Invokes all subscribers of <see cref="TimerEvent"/>
 /// </summary>
 /// <param name="sender"> The object which initialized the event </param>
 /// <param name="e"> Event arguments </param>
 protected virtual void OnTimeСome(object sender, TimerEventArgs e)
 {
     TimerEvent?.Invoke(this, e);
 }
コード例 #4
0
 // This is the method the CountdownTimer will call
 // when the countdown timer stop
 private void Listen(object sender, TimerEventArgs e)
 {
     Console.WriteLine($"{e.Message} at {e.Time}");
 }