quartz.net demo
- public class TimeJob : IJob
- {
- public void Execute(IJobExecutionContext context)
- {
- //向c:\Quartz.txt写入当前时间并换行
- System.IO.File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + "Quartz.txt", DateTime.Now + Environment.NewLine);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- //1、创建一个调度器
- var factory = new StdSchedulerFactory();
- var scheduler = factory.GetScheduler();
- scheduler.Start();
- //2、创建一个任务
- IJobDetail job = JobBuilder.Create<TimeJob>().WithIdentity("job1", "group1").Build();
- //3、创建一个触发器
- //DateTimeOffset runTime = DateBuilder.EvenMinuteDate(DateTimeOffset.UtcNow);
- ITrigger trigger = TriggerBuilder.Create()
- .WithIdentity("trigger1", "group1")
- .WithCronSchedule("0/5 * * * * ?") //5秒执行一次
- //.StartAt(runTime)
- .Build();
- //4、将任务与触发器添加到调度器中
- scheduler.ScheduleJob(job, trigger);
- //5、开始执行
- scheduler.Start();
- }
- }
============ 欢迎各位老板打赏~ ===========
与本文相关的文章
- · 区块链demo C#.NET版
- · lucene.net demo
- · C#深度学习快速入门demo
- · .NET中AOP的几种实现方案
- · The instance of entity type ‘Customer’ cannot be tracked because another instance with the same key value for {‘Id’} is already being tracked.
- · .NET8实时更新nginx ip地址归属地
- · 解决.NET Blazor子组件不刷新问题
- · .NET8如何在普通类库中引用 Microsoft.AspNetCore
- · .NET8 Mysql SSL error
- · ASP.NET Core MVC的Razor视图渲染中文乱码的问题
- · .NETCORE 依赖注入服务生命周期
- · asp.net zero改mysql