本文共 1153 字,大约阅读时间需要 3 分钟。
必须JobManager初始化
方式1:
public void Start()
{ JobManager.AddJob(() => FetchingData(), schedule => { schedule.ToRunEvery(1).Days().At(10, 8); }); }
方式2:继承Registry
public class WebSchedule : Registry
{ ILogger<WebSchedule> log; /// <summary> /// /// </summary> public WebSchedule(ILoggerFactory loggerFactory) { log = loggerFactory.CreateLogger<WebSchedule>();//立即执行,之后每2秒执行
Schedule(() => log.LogTrace("每分钟执行:" + DateTime.Now)).ToRunNow().AndEvery(1).Minutes();Schedule(() => log.LogTrace("每天执行:" + DateTime.Now)).ToRunNow().AndEvery(1).Days();
//5秒后执行一次
Schedule(() => log.LogTrace("执行一次:" + DateTime.Now)).ToRunOnceIn(5).Seconds();Schedule(() => log.LogTrace("每天21:15执行:" + DateTime.Now))
.ToRunEvery(1).Days().At(13, 55);//立即执行,之后每月的第一个星期一3点再执行
Schedule(() => { log.LogTrace("job started at " + DateTime.Now); Thread.Sleep(10000); log.LogTrace("job ended at" + DateTime.Now); }).ToRunNow().AndEvery(1).Months().OnTheFirst(DayOfWeek.Monday).At(3, 0);//多任务
//Schedule<MyJob>().AndThen<MyOtherJob>().ToRunNow(); } }调用:JobManager.Initialize(new WebSchedule(loggerFactory));
本文转自94cool博客园博客,原文链接:http://www.cnblogs.com/94cool/p/6201595.html,如需转载请自行联系原作者