// 添加定时循环任务. // 参数: 1-起始时间(从服务器获取, 单位:秒), 2-定时间隔时间(单位:秒), 3-回调. public static int AddIntervalTask(double startTicks, double cdTicks, TimedTask.TaskAction action) { int ret = timedTask.Add(startTicks, startTicks + cdTicks, action, 2, true); Logger.DEBUG("AddIntervalTask Add info: ", startTicks, cdTicks, GetNowServerTicks(), ret); return(ret); }
// 添加秒表倒计时任务. // 参数: 1-起始时间(从服务器获取, 单位:秒), 2-总计时时间(单位:秒), 3-回调, 4-是否自动移除. public static int AddSecondsTask(double startTicks, double totalTicks, TimedTask.TaskAction action, bool autoRemove = true) { Logger.DEBUG("AddSecondsTask action info: ", action); int ret = timedTask.Add(startTicks, startTicks + totalTicks, action, 3, !autoRemove); Logger.DEBUG("AddSecondsTask Add info: ", startTicks, totalTicks, GetNowServerTicks(), ret); return(ret); }
// 添加时钟定时任务. // 参数: 1-回调, 4-是否每小时任务. public static int AddHoursTask(TimedTask.TaskAction action, bool isEveryHour = false) { int serverTicks = (int)GetNowServerTicks(); int tempSeconds = serverTicks % HourSeconds; double st = serverTicks - tempSeconds; int ret = timedTask.Add(st, st + HourSeconds, action, 4, isEveryHour); Logger.DEBUG("AddHoursTask Add Info:", serverTicks, tempSeconds, st, GetNowServerTicks(), ret); return(ret); }
// 添加每日定时任务. // 参数: 1-时区(取值范围[0, 23]), 2-时钟数值(取值范围[0, 23]), 3-回调, 4-是否每天任务. public static int AddDaysTask(int timeZone, int hour, TimedTask.TaskAction action, bool isEveryDay = false) { int serverTicks = (int)GetNowServerTicks(); int utcHour = hour - timeZone; int tempSeconds = serverTicks % DaySeconds; double st = serverTicks - tempSeconds + utcHour * HourSeconds; st = st > serverTicks ? st - DaySeconds : st; int ret = timedTask.Add(st, st + DaySeconds, action, 5, isEveryDay); Logger.DEBUG("AddDaysTask Add Info:", serverTicks, hour, timeZone, utcHour, tempSeconds, st, GetNowServerTicks(), ret); return(ret); }