高端酒店网站模板经验推广
news/
2025/9/23 0:05:14/
文章来源:
高端酒店网站模板,经验推广,企业所得税5%的标准,2023楼市回暖潮无望了一、需求场景#xff1a;每天固定时间执行某个行为/动作。 一开始想用定时器#xff0c;后来无意间发现了这个插件#xff0c;感觉功能太强大了#xff0c;完美解决了我的问题。 二、下载地址#xff1a;https://www.quartz-scheduler.net/ 也可以在项目中直接使用nugut进…一、需求场景每天固定时间执行某个行为/动作。 一开始想用定时器后来无意间发现了这个插件感觉功能太强大了完美解决了我的问题。 二、下载地址https://www.quartz-scheduler.net/ 也可以在项目中直接使用nugut进行下载 三、使用方法 1.将刚才下载的热乎乎的dll引入到你的项目中 2.先写你想定时执行的任务 1 public class ModifiyStateJob : IJob
2 {
3 Task IJob.Execute(IJobExecutionContext context)
4 {
5 Console.WriteLine(现在的时间是--{1}, DateTime.Now.ToString());
6 return null;
7 }
8 } 3.用Quartz设置在每天的19:53执行该任务 1 public static async Task ListenTime()2 {3 try4 {5 // Grab the Scheduler instance from the Factory6 NameValueCollection props new NameValueCollection7 {8 { quartz.serializer.type, binary }9 };
10 StdSchedulerFactory factory new StdSchedulerFactory(props);
11 IScheduler scheduler await factory.GetScheduler();
12
13 // and start it off
14 await scheduler.Start();
15
16 // define the job and tie it to our HelloJob class
17 //
18 IJobDetail job1 JobBuilder.CreateTimeJob()
19 .WithIdentity(job1, group1)
20 .Build();
21
22
24 //每天的19点53分执行 时间的顺序是秒 分 小时 不要写错哦
25 ITrigger trigger1 TriggerBuilder.Create()
26 .WithIdentity(trigger1, group1)
27 .StartNow().WithCronSchedule(0 53 19 * * ?)
28 .Build();
29
30 // Tell quartz to schedule the job using our trigger
31 await scheduler.ScheduleJob(job1, trigger1);
32
33 // some sleep to show whats happening
34 // await Task.Delay(TimeSpan.FromSeconds(60));
35
36 // and last shut down the scheduler when you are ready to close your program
37 // await scheduler.Shutdown();
38 }
39 catch (SchedulerException se)
40 {
41 Console.WriteLine(se);
42 }
43
44
45 } 4.在入口处进行调用 1 static void Main(string[] args)
2 {
3 ListenTime().GetAwaiter().GetResult();
4 Console.Read();
5 } 5.效果如果程序不关则每天的19:53分都会运行该程序在控制台进行打印 备注自己最近写的一个表达式 //周一到周五 9点到18点每一小时执行一次ITrigger trigger1 TriggerBuilder.Create().WithIdentity(trigger1, group1).StartNow().WithCronSchedule(0 0 9-18/1 ? * MON-FRI).Build(); 写在后面的话我只是用了Quartz的一个小功能无论你是想固定时间执行任务还是间隔多长时间执行任务等等Quartz.net都能满足你的需求,只要按照指定的规则编写就可以啦。转载于:https://www.cnblogs.com/jas0203/p/10158546.html
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/910828.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!