How to schedule tasks using Quartz.Net inside a windows service?

I created a Windows service project in VS and in it I configure Quartz.Net to run the task immediately. The code that registers the task runs without exception, but the task is never executed, as far as my debugging can tell.

I cannot be sure because the debugging of a Windows service is very different. The way I do this is to programmatically launch the debugger from my code. Quartz.Net runs tasks on separate threads, but I'm not sure VS2010 can see other running threads when debugging a Windows service.

Has anyone done what I'm trying before? Any advice is appreciated.

PS. I do not want to use my own Quartz.Net service.

+4
source share
3 answers

One of the most common reasons why a task is not running is because you need to call the Start () method on the scheduler instance.

http://quartznet.sourceforge.net/faq.html#whytriggerisntfiring

But it’s hard to say what the problem is if we don’t have some piece of code that makes creating the scheduler and registering the work.

+6
source

I see that this is a little outdated, but in different search queries he came many times!

Definitely check out this article, which uses the XML configuration when creating the scheduler instance. http://miscellaneousrecipesfordotnet.blogspot.com/2012/09/quick-sample-to-schedule-tasks-using.html

If you prefer to use XML (dynamically created tasks, etc.), replace the "Run" procedure from the above article with approximately the following:

public void Run() { // construct a scheduler factory ISchedulerFactory schedulerFactory = new StdSchedulerFactory(); _scheduler = schedulerFactory.GetScheduler(); IJobDetail job = JobBuilder.Create<TaskOne>() .WithIdentity("TaskOne", "TaskOneGroup") .Build(); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("TaskOne", "TaskOneGroup") .StartNow() .WithSimpleSchedule(x => x.WithIntervalInSeconds(20).RepeatForever()) .Build(); _scheduler.ScheduleJob(job, trigger); _scheduler.TriggerJob(job.Key); _scheduler.Start(); } 

Note Using Quartz.NET 2.1.2, .NET 4

Hooray!

+4
source

I have successfully used Quart.NET before in a windows service. When the service starts, I create the Factory Scheduler and then get the Scheduler. Then I run a scheduler that implicitly reads the XML configuration specified in the App.config service.

Basic Quartz.NET setup: http://quartznet.sourceforge.net/tutorial/lesson_1.html

App.config Setup Question: http://groups.google.com/group/quartznet/browse_thread/thread/abbfbc1b65e20d63/b1c55cf5dabd3acd?lnk=gst&q=%3Cquartz%3E#b1c55cf5dabd3acd

+1
source

Source: https://habr.com/ru/post/1339238/


All Articles