Example #1
0
        /// <summary>
        /// Invokes a delegate when time elapsed.
        /// </summary>
        /// <param name="e">Arguments of event.</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown when <see cref="Clock.TimeElapsed"/> equal to null.
        /// </exception>
        protected virtual void OnTimeElapsed(ClockEventArgs e)
        {
            if (ReferenceEquals(TimeElapsed, null))
            {
                throw new ArgumentNullException(nameof(TimeElapsed));
            }

            TimeElapsed(this, e);
        }
Example #2
0
        /// <summary>
        /// Starts clock and after the end of time calls an event.
        /// </summary>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown when <see cref="Clock.Interval"/> less than or equal to 0.
        /// </exception>
        public void Start()
        {
            if (Interval <= 0)
            {
                throw new ArgumentOutOfRangeException("Interval must be greater than null.", nameof(Interval));
            }

            Thread.Sleep(Interval);

            ClockEventArgs eventArgs = new ClockEventArgs()
            {
                Date = DateTime.Now, IntervalInMilliseconds = Interval
            };

            OnTimeElapsed(eventArgs);
        }