如何在随机时间(0-24)每天触发一个功能 或者在石英的给定时间范围内(上午9:00 - 下午6:00)每天开火一次。
例如,今天它将在上午11:20,明天04:12 pm工作
提前致谢。
答案 0 :(得分:0)
我建议这样做:
创建代码的代码可能是这样的:
public DailyTimeIntervalTriggerImpl GetNextTrigger(int minHour, int maxHour)
{
var random = new Random();
int randomHour = random.Next(minHour, maxHour + 1);
int randomMinute = random.Next(0, 60);
var nextDayOfWeek = DateTime.Now.AddDays(1).DayOfWeek;
var daysOfWeek = new Quartz.Collection.HashSet<System.DayOfWeek>() { nextDayOfWeek };
var trigger = new DailyTimeIntervalTriggerImpl
{
DaysOfWeek = daysOfWeek,
StartTimeUtc = DateTime.UtcNow,
StartTimeOfDay = new TimeOfDay(randomHour, randomMinute, 0),
TimeZone = TimeZoneInfo.Utc
};
return trigger;
}