转载

Quartz.net定时任务框架的使用

一:Nuget添加Quartz.net和Topshelf

二:新建HelloJob类继承IJob

public class HelloJob : IJob

{
public async Task Execute(IJobExecutionContext context)
{
Console.WriteLine("HelloJob is executing.");
}
}

三:调用

public static async Task Demo()

{

ISchedulerFactory schedFact = new StdSchedulerFactory();

// get a scheduler

IScheduler sched =await schedFact.GetScheduler();

sched.Start();

// define the job and tie it to our HelloJob class

IJobDetail job = JobBuilder.Create<HelloJob>()

.WithIdentity("myJob", "group1")

.Build();

// Trigger the job to run now, and then every 40 seconds

ITrigger trigger = TriggerBuilder.Create()

.WithIdentity("myTrigger", "group1")

.StartNow()

.WithSimpleSchedule(x => x

.WithIntervalInSeconds(5)

.RepeatForever())

.Build();

sched.ScheduleJob(job, trigger);

}

这是一个简单的定时器,每5秒执行HelloJob方法

https://www.cnblogs.com/pingming/p/4999228.html

demo 下载:https://download.csdn.net/user/qq_27169469/uploads

原文  https://www.maiyewang.com/2019/10/17/quartz-net定时任务框架的使用/
正文到此结束
Loading...