上一篇里介绍了job和trigger的常用方法,这一节将介绍calendar,它的作用是排除特定的日期时间。
var sche = stdschedulerfactory.getdefaultscheduler(); sche.start(); //使任务在10点到11点间不再执行 dailycalendar cale = new dailycalendar( datebuilder.dateof(10, 0, 0).datetime, datebuilder.dateof(11, 0, 0).datetime ); sche.addcalendar("mycalendar", cale, true, true);
var sche = stdschedulerfactory.getdefaultscheduler(); sche.start(); weeklycalendar cale = new weeklycalendar(); cale.setdayexcluded(dayofweek.thursday, true); //让星期四不触发schedule //cale.setdayexcluded(dayofweek.thursday, false); //让星期四触发schedule sche.addcalendar("mycalendar", cale, true, true);
var sche = stdschedulerfactory.getdefaultscheduler(); sche.start(); holidaycalendar cale = new holidaycalendar(); cale.addexcludeddate(datetime.now.addyears(-1)); //排除去年的今天不处理 cale.addexcludeddate(datetime.now); //排除今天不处理 sche.addcalendar("mycalendar", cale, true, true);
var sche = stdschedulerfactory.getdefaultscheduler(); sche.start(); monthlycalendar cale = new monthlycalendar(); cale.setdayexcluded(25, true); //排除每个月25号执行 sche.addcalendar("mycalendar", cale, true, true);
var sche = stdschedulerfactory.getdefaultscheduler(); sche.start(); annualcalendar cale = new annualcalendar(); //12月25号不执行 cale.setdayexcluded(new datetimeoffset(2018, 12, 25, 12, 0, 0, timespan.fromhours(8)), true); sche.addcalendar("mycalendar", cale, true, true);
var sche = stdschedulerfactory.getdefaultscheduler(); sche.start(); //只在营业时间执行8am-5pm croncalendar cale = new croncalendar("* * 0-7,18-23 ? * *"); sche.addcalendar("mycalendar", cale, true, true);
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论