如何在 Windows 服务中使用 Quartz.Net 安排任务?
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
作业不执行的最常见原因之一是您需要在调度程序实例上调用 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.
我发现这有点过时了,但它在各种搜索中出现了很多次!
请务必查看这篇文章,它在实例化调度程序时使用 XML 配置。
http://miscellaneousrecipesfordotnet.blogspot.com/2012 /09/quick-sample-to-schedule-tasks-using.html
如果您不想使用 XML(动态创建的任务等),请将上面文章中的“运行”过程替换为类似以下内容:
注意 - 使用 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:
Note - Using Quartz .NET 2.1.2, .NET 4
Cheers!
我之前已经在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