执行计划任务的方法 - Windows / .NET

发布于 2024-11-25 22:13:43 字数 284 浏览 0 评论 0原文

我的问题很简单。 我有一个应用程序应该每天自动执行一次。我以前没有处理过这种情况的经验(前段时间我使用过 IBM Control-M,但猜测它更完整、更复杂且更昂贵 =))

我考虑了两种可能的解决方案:

  • 在 Windows 任务计划程序中创建任务,它将执行应用程序;
  • 将应用程序实现为 24/7 运行的 Window 服务,但仅根据当前时间执行所需的操作。

每种方法的优点/缺点是什么?

还有其他方法可以做到这一点吗?

提前致谢。

My issue is pretty simple.
I have an application that should be executed automatically once a day. I have no prior experience with this kind of scenario (some time ago I worked with IBM Control-M but guess that it is way more complete, complex and expensive =))

I thought about two possible solutions:

  • Creating a Task inside Windows Task Scheduler, which would execute the application;
  • Implement the application as a Window Service which would run 24/7, but only would perform the needed actions depending on the current time.

Which are the advantages/disadvantages of each approach?

Is there another way to do this?

Thanks in advance.

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

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

发布评论

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

评论(4

極樂鬼 2024-12-02 22:13:43

如果它每天(左右)只执行一次,那么只需将其作为由 Windows 任务计划程序执行的常规命令行应用程序即可。任务调度程序已经拥有确定何时启动程序、传入参数以及与任务调度相关的任何其他内容所需的所有 UI。

将此类函数作为 Windows 服务执行的唯一真正原因是它需要比每分钟一次更高的执行分辨率。然而,Windows 服务的主要缺点是您必须管理启动频率/时间的逻辑。另一个问题是应用程序始终在运行,如果您的代码有问题,这可能会导致内存泄漏。

If it only executes once a day (or so) then just do it as a regular command line app that is executed by the windows task scheduler. Task scheduler already has all of the UI necessary to determine when to kick off the program, pass in parameters and anything else related to the scheduling of the task.

The only real reason to do this type of function as a windows service is if it needs higher execution resolution than once a minute. However, the main downside to a windows service is that you would have to manage the logic for how often/when to kick it off. Another one is that the app is always running, which leaves open the possibility for leaked memory if your code has issues.

依 靠 2024-12-02 22:13:43

在 Unix/Linux 上,您可以使用 cron 作业来安排要执行的任务。 MS Windows 的版本称为任务计划程序,它已经是24/7 运行并根据时间执行所需操作的服务。

使用任务计划程序创建重复任务来运行您的应用程序。创建、安装和配置服务应用程序并非易事。这是一个比创建标准表单或命令行应用程序复杂得多的过程,而且您无论如何都不需要这样做。

On Unix/Linux you would use a cron job schedule a task to be executed. MS Windows' version is called the Task Scheduler and it is already a service that run 24/7 and performs the needed actions depending on the time.

Create a repeating task with the Task Scheduler to run your application. Creating, installing and configuring a service application is not exactly trivial. It's a much more involved process than creating a standard Forms or command line app and you don't need to do it anyway.

归途 2024-12-02 22:13:43
寒冷纷飞旳雪 2024-12-02 22:13:43

另一个可能感兴趣的库是 Quartz.NET

Another library that might be of interest is Quartz.NET

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