这是更好地用于经常性工作:服务或计划任务? [英] Which is better to use for a recurring job: Service or Scheduled Task?

查看:187
本文介绍了这是更好地用于经常性工作:服务或计划任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要每30秒运行任务。我可以做两件事情之一:

I have a task that needs to run every 30 seconds. I can do one of two things:


  1. 编写,一旦运行任务,等待30秒的命令行应用程序,运行它再次,然后退出。我可以在Windows中使用计划任务安排此任务运行每分钟

  1. Write a command line app that runs the task once, waits 30 seconds, runs it again and then exits. I can schedule this task with Scheduled Tasks in Windows to run every minute

编写重复运行任务,而在每次运行之间等待30秒的服务。

Write a Service that runs a task repeatedly while waiting 30 seconds in between each run.

1号更是微不足道,在我看来,我会选择在默认情况下做这种方式。我是不是wimping了呢?是否有一个原因,我应该使这一服务,而不是计划的任务?什么是两者的利弊,这将你到底挑

Number 1 is more trivial, in my opinion and I would opt to do it this way by default. Am I wimping out? Is there a reason why I should make this a Service and not a scheduled task? What are the pros and cons of both and which would you pick in the end?

推荐答案

I读一篇好的博客贴子这个问题最近。它进入了很多很好的原因,你应该的的写一个服务运行循环作业。

I read a nice blog post about this question recently. It goes into a lot of good reasons why you should not write a service to run a recurring job. Additionally, this question has been asked before:

http://stackoverflow.com/questions/390307/windows-service-vs-scheduled-task
http://stackoverflow.com/questions/767490/windows-service-or-scheduled-task哪位酮待办事项-我们-宁愿

利用所调度的任务的一个优点是,如果有涉及运行的服务的一些潜在风险如内存泄漏,或挂网络连接,那么Windows服务可能会挂aroung很长一段时间,造成负面影响其他用户。另一方面,预定任务写入短的运行,所以,即使它的泄漏,效果被最小化。

One advantage of using the scheduled task, is that if there is some potential risk involved with running the service such as a memory leak or hanging network connection, then the windows service can potentially hang aroung for a long time, adversely affecting other users. On the other hand, the scheduled task is written to be short running, so even if it does leak, the effect is minimised.

在另一方面,有人在一个上述问题评论说,调度有1分钟的范围内某处精度的限制,所以你可能会看到,调度程序无法运行,每30秒准确你的任务。

On the other hand, someone in one of the above questions commented that the scheduler has a limit of accuracy of somewhere in the range of 1 minute, so you may see that the scheduler is unable to run your task every 30 seconds with accuracy.

显然有一些折衷的考虑,但希望这会帮助你做出一个好的决定。

Obviously there are a number of tradeoffs to consider, but hopefully this will help you make a good decision.

这篇关于这是更好地用于经常性工作:服务或计划任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆