Windows 服务或计划任务,我们更喜欢哪一个? [英] Windows Service or Scheduled Task, which one do we prefer?

查看:31
本文介绍了Windows 服务或计划任务,我们更喜欢哪一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我们需要编写一个周期性运行的程序,我们更喜欢哪种方式?编写 Windows 服务或编写作为计划任务工作的控制台应用程序?

If we need to write a program that works periodically, which way do we prefer? Writing a windows service or writing a console application which works as scheduled task?

推荐答案

如果可以,我建议将流程作为计划任务运行,并仅在需要时编写服务.服务(正确)编写起来要困难得多,如果您按任何类型的时间表运行您的进程,那么使用 Windows 调度程序比尝试构建自己的调度程序要好得多(在服务).

I would suggest running the process as a scheduled task if you can, and writing a service only if you need to. Services are quite a bit more difficult to write (correctly), and if you're running your process on a schedule of any sort, you're much better off using the windows scheduler than attempting to build a scheduler of your own (within the servce).

  • Windows 任务调度程序比您自制的调度程序更高效
  • Windows 任务计划程序提供了许多选项,您几乎肯定不会尝试复制这些选项,但以后可能会发现它们很有用
  • 如果您构建了一个服务,如果您想更改决定在什么条件下运行任务的逻辑,您就必须重新编译程序.如果您使用调度程序,只需翻转一些选项即可完成.

如果您想在两者之间做出决定,那么显然使用 Task Scheduler 是一个可行的选择.如果使用 Task Scheduler 是一个可行的选择,那么构建服务几乎肯定是错误的选择.

If you're trying to decide between the two, then obviously using the Task Scheduler is a viable option. And if using the Task Scheduler is a viable option, then building a service is almost certainly the wrong choice.

这篇关于Windows 服务或计划任务,我们更喜欢哪一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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