【Quartz.NET 3.x Tutorial】Quartz.NET - Lesson 1: Using Quartz
Before you can use the scheduler, it needs to be instantiated (who’d have guessed?). To do this, you use an implementor of ISchedulerFactory.
Once a scheduler is instantiated(v. 实例化(instantiate的过去分词);具现化,实体化), it can be started, placed in stand-by mode, and shutdown. Note that once a scheduler is shutdown, it cannot be restarted without being re-instantiated. Triggers do not fire (jobs do not execute) until the scheduler has been started, nor while it is in the paused state.
Here’s a quick snippet of code, that instantiates and starts a scheduler, and schedules a job for execution:
Using Quartz.NET
// construct a scheduler factory NameValueCollection props = new NameValueCollection { { "quartz.serializer.type", "binary" } }; StdSchedulerFactory factory = new StdSchedulerFactory(props); // get a scheduler IScheduler sched = await factory.GetScheduler(); await 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(40) .RepeatForever()) .Build(); await sched.ScheduleJob(job, trigger);
As you can see, working with Quartz.NET is rather simple. In Lesson 2 we’ll give a quick overview of Jobs and Triggers, so that you can more fully understand this example.
https://www.quartz-scheduler.net/documentation/quartz-3.x/tutorial/using-quartz.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】凌霞软件回馈社区,携手博客园推出1Panel与Halo联合会员
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步