private void Run(DateTime time)
        {
            DateTime now = time;

            // pause time temporarily.
            timer.Enabled = false;

            // run tasks.
            // find the min interval to run next task.
            int minInterval = int.MaxValue;

            lock (locker)
            {
                foreach (ITask task in tasks.Values)
                {
                    // ignore when task isn't enable or next time is illegal or not the time.
                    if (!task.Enable || task.NextTime == default(DateTime))
                    {
                        continue;
                    }

                    // if it's not the time to run this task, calculat the interval.
                    int interval;
                    if (task.NextTime > now)
                    {
                        interval    = (int)(task.NextTime - now).TotalMilliseconds;
                        minInterval = interval < minInterval ? interval : minInterval;
                        continue;
                    }

                    // if run this task, then create a thread to run it and generate time of next running.
                    task.LastTime = now;
                    task.NextTime = task.GenerateNextTime(now);
                    new Task(() =>
                    {
                        task.Run(now);
                    }).Start();

                    // calculate the min interval.
                    interval    = (int)(task.NextTime - now).TotalMilliseconds;
                    minInterval = interval < minInterval ? interval : minInterval;

                    if (willCacheTime)
                    {
                        TaskTimeCache.GetInstance().Update(task.Name, now, task.NextTime);
                    }
                }
            }

            timer.Interval = minInterval;
            timer.Enabled  = true;
        }
        /// <summary>
        /// Get the singleton instance.
        /// </summary>
        /// <returns></returns>
        public static TaskTimeCache GetInstance()
        {
            if (instance == null)
            {
                lock (locker)
                {
                    if (instance == null)
                    {
                        instance = new TaskTimeCache();
                    }
                }
            }

            return(instance);
        }