如何在 Windows 服务中使用 Quartz.Net 安排任务?

发布于 2024-10-17 00:01:19 字数 289 浏览 4 评论 0原文

我在 VS 中创建了一个 Windows 服务项目,并在其中配置 Quartz.Net 以立即运行任务。注册任务的代码运行时没有异常,但据我的调试所知,该任务从未执行。

我不能确定,因为调试 Windows 服务是非常不同的。我这样做的方法是从我的代码中以编程方式启动调试器。 Quartz.Net 在单独的线程上运行作业,但我不确定 VS2010 在调试 Windows 服务时是否可以看到其他正在运行的线程。

有人做过我之前尝试过的事情吗?任何提示表示赞赏。

附言。我不想使用 Quartz.Net 自己的服务。

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

I can't be sure because debugging a Windows Service is very different. The way I do it is to programatically launching the debugger from my code. Quartz.Net runs jobs on a separate threads, but I'm not sure if VS2010 can see other running threads when debugging a Windows Service.

Has anyone done what I'm trying before? Any tips are appreciated.

PS. I don't want to use Quartz.Net's own Service.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

仅一夜美梦 2024-10-24 00:01:19

作业不执行的最常见原因之一是您需要在调度程序实例上调用 Start() 方法。

但是

很难如果我们没有某种执行调度程序创建和作业注册的代码片段,请说明问题是什么。

One of the most common reasons a job doesn't execute, 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 sort of snippet of the code that does the scheduler creation and job registration.

通知家属抬走 2024-10-24 00:01:19

我发现这有点过时了,但它在各种搜索中出现了很多次!

请务必查看这篇文章,它在实例化调度程序时使用 XML 配置。
http://miscellaneousrecipesfordotnet.blogspot.com/2012 /09/quick-sample-to-schedule-tasks-using.html

如果您不想使用 XML(动态创建的任务等),请将上面文章中的“运行”过程替换为类似以下内容:

    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();
    }

注意 - 使用 Quartz .NET 2.1.2、.NET 4

干杯!

I see that this is a bit dated, but it came up many times in various searches!

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

In case you would rather not use XML (dynamically created tasks and such), replace the "Run" procedure from the article above with something like this:

    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

Cheers!

迎风吟唱 2024-10-24 00:01:19

我之前已经在Windows服务中成功使用过Quart.NET。当服务启动时,我创建调度程序工厂,然后获取调度程序。然后,我启动调度程序,该调度程序隐式读取我在服务的 App.config 中指定的配置 XML。

Quartz.NET 基本设置:http://quartznet.sourceforge.net/tutorial/lesson_1.html

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

I have successfully used Quart.NET before in a Windows service. When the service starts-up I create the Scheduler Factory and then get the Scheduler. I then start the scheduler which implicitly reads in the configuration XML I have specified in the App.config of the service.

Quartz.NET basic 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文