Ejemplo n.º 1
0
        /// <summary>
        /// 添加新任务
        /// </summary>
        /// <param name="run">任务执行委托</param>
        /// <param name="type">调用类型</param>
        /// <param name="onError">任务执行出错委托,停止任务参数null</param>
        /// <param name="runTime">执行时间</param>
        private void add(object run, thread.callType type, Action <Exception> onError, DateTime runTime)
        {
            bool isThread     = false;
            long runTimeTicks = runTime.Ticks;

            Monitor.Enter(taskLock);
            try
            {
                taskHeap.Push(runTimeTicks, new taskInfo {
                    Call = run, Type = type, OnError = onError
                });
                if (runTimeTicks < nearTime)
                {
                    timer.Stop();
                    nearTime = runTimeTicks;
                    double time = (runTime - date.Now).TotalMilliseconds + 1;
                    if (time > 0)
                    {
                        timer.Interval = Math.Min(time, int.MaxValue);
                        timer.Start();
                    }
                    else
                    {
                        isThread = true;
                    }
                }
            }
            finally { Monitor.Exit(taskLock); }
            if (isThread)
            {
                threadPool.FastStart(this, thread.callType.TimerTaskRun);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加新任务
        /// </summary>
        /// <param name="task">任务信息</param>
        /// <param name="runTime">执行时间</param>
        private void add(task task, DateTime runTime)
        {
            bool isThread     = false;
            long runTimeTicks = runTime.Ticks;

            Monitor.Enter(taskLock);
            try
            {
                taskHeap.Push(runTimeTicks, task);
                if (runTimeTicks < nearTime)
                {
                    timer.Stop();
                    nearTime = runTimeTicks;
                    double time = (runTime - date.Now).TotalMilliseconds + 1;
                    if (time > 0)
                    {
                        timer.Interval = Math.Min(time, int.MaxValue);
                        timer.Start();
                    }
                    else
                    {
                        isThread = true;
                    }
                }
            }
            finally { Monitor.Exit(taskLock); }
            if (isThread)
            {
                threadPool.FastStart(this, thread.callType.TimerCancelTaskRun);
            }
        }