コード例 #1
0
        private TimeSpan TimeUntilNext(T now)
        {
            while (true)
            {
                SimpleTimer fired = null;
                TimeSpan    waitTime;
                lock (this.lockObject)
                {
                    if (this.timers.Count < 1)
                    {
                        waitTime = TimeSpan.FromSeconds(1000);
                    }
                    else
                    {
                        // How long till the first timer?
                        SimpleTimer timer = this.timers.First();
                        waitTime = this.SubtractTimes(timer.Time, now);
                        if (waitTime <= TimeSpan.Zero)
                        {
                            waitTime = TimeSpan.Zero;
                            fired    = timer;
                            this.timers.Remove(fired);
                        }
                    }
                }

                if (fired != null)
                {
                    fired.Callback();
                }
                else
                {
                    return(waitTime);
                }
            }
        }