/// <summary> /// 添加定时任务 /// </summary> /// <param name="week">星期</param> /// <param name="hour">指定时间</param> /// <param name="minute">指定时间</param> /// <param name="second">指定时间</param> /// <param name="callbacks">执行的方法</param> public void AddTiming(DayOfWeek week, int hour, int minute, int second, params TaskEntity[] callbacks) { var cycle = new TaskCycle { TimeType = EumTimeType.Timing, Tasks = callbacks, Week = week, Hour = hour, Minute = minute, Second = second }; foreach (var taskEntity in callbacks) { taskEntity.TaskCycle = cycle; } _taskList.Add(cycle); }
/// <summary> /// 添加间隔任务 /// </summary> /// <param name="callbacks">执行的方法</param> /// <param name="day">间隔时间</param> /// <param name="hour">间隔时间</param> /// <param name="minute">间隔时间</param> /// <param name="second">间隔时间</param> /// <param name="millisecond">间隔时间</param> public void AddInterval(int day, int hour, int minute, int second, int millisecond, params TaskEntity[] callbacks) { var cycle = new TaskCycle { TimeType = EumTimeType.Interval, Tasks = callbacks, Day = day, Hour = hour, Minute = minute, Second = second, Millisecond = millisecond }; foreach (var taskEntity in callbacks) { taskEntity.TaskCycle = cycle; } _taskList.Add(cycle); }
private string ConvertShow(TaskCycle task) { var str = new StringBuilder(); if (task.TimeType == EumTimeType.Timing) { str.Append(task.Day > 0 ? $"每月{task.Day}号" : $"每天"); str.Append($"{task.Hour}时{task.Minute}分{task.Second}秒"); } else { str.Append($"每隔"); if (task.Day > 0) { str.Append($"{task.Day}天"); } if (task.Hour > 0) { str.Append($"{task.Hour}时"); } if (task.Minute > 0) { str.Append($"{task.Minute}分"); } if (task.Second > 0) { str.Append($"{task.Second}秒"); } if (task.Millisecond > 0) { str.Append($"{task.Millisecond}毫秒"); } } return(str + "执行"); }