/// <summary> /// 二维秒级定时任务节点 /// </summary> /// <param name="taskArray">二维定时任务数组</param> /// <param name="timeoutSeconds">第一次执行任务间隔的秒数</param> /// <param name="threadMode">执行任务的线程模式</param> /// <param name="KeepMode">定时任务继续模式</param> /// <param name="keepSeconds">继续执行间隔秒数,0 表示不继续执行</param> internal SecondTimerTaskNode(SecondTimerTaskArray taskArray, int timeoutSeconds, SecondTimerThreadMode threadMode, SecondTimerKeepMode KeepMode, int keepSeconds) { switch (KeepMode) { case SecondTimerKeepMode.After: case SecondTimerKeepMode.Before: if (keepSeconds <= 0) { KeepMode = SecondTimerKeepMode.Once; } else { this.keepSeconds = keepSeconds; if (timeoutSeconds < 0) { timeoutSeconds = 0; } } break; } this.taskArray = taskArray; TimeoutSeconds = SecondTimer.CurrentSeconds + timeoutSeconds; this.threadMode = threadMode; this.KeepMode = KeepMode; }
public void Append(Action task, DateTime timeout, SecondTimerThreadMode threadMode = SecondTimerThreadMode.TaskRun, SecondTimerKeepMode KeepMode = SecondTimerKeepMode.Once, int keepSeconds = 0) #endif { long ticks = timeout.Ticks - (timeout.Kind == DateTimeKind.Utc ? SecondTimer.UtcNow : SecondTimer.Now).Ticks; long timeoutSeconds = ticks > 0 ? (ticks + (TimeSpan.TicksPerSecond - 1)) / TimeSpan.TicksPerSecond : 0; Append(new SecondTimerActionTask(this, task, (int)Math.Min(timeoutSeconds, int.MaxValue), threadMode, KeepMode, keepSeconds)); }
/// <summary> /// 周期定时任务 /// </summary> /// <param name="run">定时任务</param> /// <param name="timerPeriodic">定时器周期数据</param> /// <param name="threadMode">定时任务线程模式</param> /// <param name="isSkipTime">下一次执行是否跳过当前时间,比如电脑休眠以后会产生时间差</param> public TimerPeriodicTask(Action run, TimerPeriodic timerPeriodic, SecondTimerThreadMode threadMode = SecondTimerThreadMode.TinyBackgroundThreadPool, bool isSkipTime = true) { if (run == null) { throw new ArgumentNullException(); } this.run = run; this.timerPeriodic = timerPeriodic; this.threadMode = threadMode; this.isSkipTime = isSkipTime; SecondTimer.TaskArray.Append(runHandle = Run, runTime = timerPeriodic.GetStartRunTime(intervalTicks = timerPeriodic.GetIntervalTicks()), threadMode); }
internal SecondTimerActionTask(SecondTimerTaskArray taskArray, Action task, int timeoutSeconds, SecondTimerThreadMode threadMode = SecondTimerThreadMode.TaskRun, SecondTimerKeepMode KeepMode = SecondTimerKeepMode.Once, int keepSeconds = 0) #endif : base(taskArray, timeoutSeconds, threadMode, KeepMode, keepSeconds) { this.task = task; }
/// <summary> /// 二维秒级定时委托任务节点 /// </summary> /// <param name="taskArray">二维定时任务数组</param> /// <param name="task">委托任务</param> /// <param name="timeoutSeconds">第一次执行任务间隔的秒数</param> /// <param name="threadMode">执行任务的线程模式</param> /// <param name="KeepMode">定时任务继续模式</param> /// <param name="keepSeconds">继续执行间隔秒数,0 表示不继续执行</param> #if DOTNET2 || DOTNET4 || UNITY3D internal SecondTimerActionTask(SecondTimerTaskArray taskArray, Action task, int timeoutSeconds, SecondTimerThreadMode threadMode = SecondTimerThreadMode.TinyBackgroundThreadPool, SecondTimerKeepMode KeepMode = SecondTimerKeepMode.Once, int keepSeconds = 0)
internal void AppendMinute(Action task, SecondTimerThreadMode threadMode = SecondTimerThreadMode.Synchronous, SecondTimerKeepMode KeepMode = SecondTimerKeepMode.Before) { Append(new SecondTimerActionTask(this, task, 60, threadMode, KeepMode, 60)); }
/// <summary> /// 添加定时委托任务 /// </summary> /// <param name="task">委托任务</param> /// <param name="timeout">第一次执行任务时间</param> /// <param name="threadMode">执行任务的线程模式</param> /// <param name="KeepMode">定时任务继续模式</param> /// <param name="keepSeconds">继续执行间隔秒数,0 表示不继续执行</param> #if DOTNET2 || DOTNET4 || UNITY3D public void Append(Action task, DateTime timeout, SecondTimerThreadMode threadMode = SecondTimerThreadMode.TinyBackgroundThreadPool, SecondTimerKeepMode KeepMode = SecondTimerKeepMode.Once, int keepSeconds = 0)
public void Append(Action task, int timeoutSeconds, SecondTimerThreadMode threadMode = SecondTimerThreadMode.TaskRun, SecondTimerKeepMode KeepMode = SecondTimerKeepMode.Once, int keepSeconds = 0) #endif { Append(new SecondTimerActionTask(this, task, timeoutSeconds, threadMode, KeepMode, keepSeconds)); }
internal void AppendNext(Action task, SecondTimerThreadMode threadMode = SecondTimerThreadMode.TinyBackgroundThreadPool) { Append(new SecondTimerActionTask(this, task, 1, threadMode)); }