コード例 #1
0
        /// <summary>
        /// Adds a new <see cref="IScheduler"/> with a specified period.
        /// </summary>
        /// <param name="period">The period of the new <see cref="ISchedule"/>.</param>
        /// <param name="enable">If set to <see langword="true"/>, enables the new <see cref="ISchedule"/> immediately.</param>
        /// <returns>
        /// Returns the new <see cref="ISchedule"/>.
        /// </returns>
        /// <exception cref="ArgumentException">Is thrown when the new trigger couldn't be created.</exception>
        public ISchedule Add(TimeSpan period, bool enable)
        {
            ISchedule trigger = new SignalSchedule(period, this);

            trigger.Enabled = enable;

            try
            {
                if (this.listLock.TryEnterWriteLock(WaitOnLockInMilliseconds))
                {
                    this.triggerList.Add(trigger);
                    if (this.triggerList.Count > 1)
                    {
                        this.RecalculateTimerPeriod();
                    }
                    else
                    {
                        this.SetTimerProperties(trigger.Period, true);
                    }
                }
                else
                {
                    throw new ArgumentException("Couldn't add the new ISchedule. List is blocked.");
                }
            }
            finally
            {
                this.listLock.ExitWriteLock();
            }

            return(trigger);
        }
コード例 #2
0
        /// <summary>
        /// Adds a new <see cref="IScheduler"/> with a specified period.
        /// </summary>
        /// <param name="period">The period of the new <see cref="ISchedule"/>.</param>
        /// <param name="enable">If set to <see langword="true"/>, enables the new <see cref="ISchedule"/> immediately.</param>
        /// <returns>
        /// Returns the new <see cref="ISchedule"/>.
        /// </returns>
        /// <exception cref="ArgumentException">Is thrown when the new trigger couldn't be created.</exception>
        public ISchedule Add(TimeSpan period, bool enable)
        {
            ISchedule trigger = new SignalSchedule(period, this);
            trigger.Enabled = enable;

            try
            {
                if (this.listLock.TryEnterWriteLock(WaitOnLockInMilliseconds))
                {
                    this.triggerList.Add(trigger);
                    if (this.triggerList.Count > 1)
                    {
                        this.RecalculateTimerPeriod();
                    }
                    else
                    {
                        this.SetTimerProperties(trigger.Period, true);
                    }
                }
                else
                {
                    throw new ArgumentException("Couldn't add the new ISchedule. List is blocked.");
                }
            }
            finally
            {
                this.listLock.ExitWriteLock();
            }

            return trigger;
        }