public void Add(Action run, DateTime runTime, TimerTaskThreadType threadType = TimerTaskThreadType.ThreadPool) { if (run != null) { add(run, Thread.CallType.Action, threadType, runTime); } }
/// <summary> /// 周期定时任务 /// </summary> /// <param name="run">定时任务</param> /// <param name="timerPeriodic">定时器周期数据</param> /// <param name="threadType">定时任务线程模式</param> public TimerPeriodicTask(Action run, TimerPeriodic timerPeriodic, TimerTaskThreadType threadType = TimerTaskThreadType.ThreadPool) { if (run == null) { throw new ArgumentNullException(); } this.run = run; this.threadType = threadType; TimerTask.Default.Add(runHandle = Run, runTime = timerPeriodic.GetStartRunTime(intervalTicks = timerPeriodic.GetIntervalTicks()), threadType); }
/// <summary> /// 添加新任务 /// </summary> /// <param name="value">任务委托</param> /// <param name="type">调用类型</param> /// <param name="threadType">定时任务线程模式</param> /// <param name="runTime">执行时间</param> private void add(object value, Thread.CallType type, TimerTaskThreadType threadType, DateTime runTime) { long runTimeTicks = runTime.Ticks; TimerTaskInfo taskInfo = new TimerTaskInfo { Value = value, CallType = type, ThreadType = threadType }; Monitor.Enter(taskLock); try { taskHeap.Push(runTimeTicks, ref taskInfo); if (runTimeTicks < nearTime) { nearTime = runTimeTicks; } } finally { Monitor.Exit(taskLock); } }