Windows 任务调度程序用于调度代码重复运行的可靠性如何?

发布于 2024-07-16 16:30:40 字数 144 浏览 7 评论 0原文

我有一些代码需要驻留在 Windows Server 2003 计算机上并每分钟运行一次。

建议的处理方法是什么? 是否可以将其设计为控制台服务并让任务调度程序每分钟都执行它? (这可能吗?)我应该把它吸收并把它写成一个 Windows 服务吗?

I have a bit of code that needs to sit on a windows server 2003 machine and run every minute.

What is the recommended way of handling this? Is it ok to design it as a console service and just have the task scheduler hit it ever minute? (is that even possible?) Should I just suck it up and write it as a windows service?

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

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

发布评论

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

评论(8

小…楫夜泊 2024-07-23 16:30:40

由于它需要每分钟运行一次,我建议编写一个 Windows 服务。 它不是很复杂,如果您以前从未这样做过,那么学习它是如何完成的对您来说会很棒。

我不建议每分钟调用计划任务。

Since it needs to run every single minute, I would suggest writing a Windows Service. It is not very complicated, and if you never did this before, it would be great for you to learn how it is done.

Calling the scheduled task every minute is not something I would recommend.

飘然心甜 2024-07-23 16:30:40

我想说的是,忍住吧,把它写成一个 Windows 服务。 我还没有发现计划任务非常可靠,当它不运行时,我还没有找到一种简单的方法来找出它不运行的原因。

I would say suck it up and write it as a Windows service. I've not found scheduled tasks to be very reliable and when it doesn't run, I have yet to find an easy way to find out why it hasn't.

孤芳又自赏 2024-07-23 16:30:40

Windows 计划任务对于我们的目的来说相当可靠,并且由于其易于安装和高级恢复功能,我们在几乎所有情况下都比 Windows 服务更喜欢它们。 如果编写的部分代码最终被锁定或循环在不应该出现的代码段中,Windows 服务的始终开启特性可能最终会成为问题。我们通常将代码编写在然后

Init();
Run();
CleanUp();

,作为计划任务的一部分,我们对进程可以运行的时间设置时间限制,如果运行时间更长,则将其杀死。 如果我们确实有一段代码出现问题,计划任务将杀死它,并且该进程将在下一分钟启动。

Windows Scheduled Tasks has been fairly reliable for our purposes and we favor them in almost all cases over Windows Services due to their ease of installing and advanced recovery features. The always on nature of a windows service could end up being a problem if a part of the code that was written ends ups getting locked up or looped in a piece of code that it shouldn't be in. We generally write our code in a fashion similar to this

Init();
Run();
CleanUp();

Then as part of the Scheduled Task we put a time limit on how long the process can run and have it kill the process if it runs for longer. If we do have a piece of code that is having trouble Scheduled Tasks will kill it and the process will start up in the next minute.

梦魇绽荼蘼 2024-07-23 16:30:40

如果您需要让它每分钟运行一次,我会将其构建为 Windows 服务。 我不会将调度程序用于日常任务之外的任何事情。

if you need to have it run every minute, I would build it as a windows service. I wouldn't use the scheduler for anything less than a daily task.

猫七 2024-07-23 16:30:40

我想说这取决于它在做什么,但总的来说我总是赞成拥有最少的层数。 如果您将其编写为控制台服务并使用任务计划程序,那么您有两个地方可以继续前进。

如果您将其编写为 Windows 服务,那么您只有更少的地方需要检查,以防出现问题。

I would say that it depends on what it was doing, but in general I am always in favor of having the fewest layers. If you write it as a console service and use the task scheduler then you have two places to maintain going forward.

If you write it as a windows service then you only have one fewer places to check in case something goes wrong.

意中人 2024-07-23 16:30:40

在搜索预定服务帮助时,我遇到了一个非常好的 乔恩·加洛韦的文章

如果使用 Windows 服务来执行计划任务,则存在各种缺点。 我同意了。 我建议使用任务计划,实现简单。 请参考实现任务调度程序的详细信息。 希望这些信息有助于最终确定实施方法。

While searching for scheduled service help, i came across to a very good article by Jon Galloway.

There are various diadvantages if a windows service is used for scheduled task. I agreed with it. I would suggest to use Task Scheduled, simple in implementation. Please refer to detailed information of implementing the task scheduler. Hope this info helps in finalizing the implementation approach.

_蜘蛛 2024-07-23 16:30:40

唯一需要考虑的另一点是,如果您的工作涉及某种数据库交互,请考虑研究数据库提供的集成/调度服务。

例如,为 SQL Server 相关服务创建 SSIS 包可能看起来有点大材小用,但它可以与环境很好地集成,并且已经有自己的日志记录/错误检查机制。

The only other point to consider, is that if you're job involves some kind of database interaction, consider looking into the integration/scheduling services provided by your database.

For example, creating an SSIS package for your SQL Server related service may seem a bit like overkill, but it can be integrated nicely with the environment and will have its own logging/error checking mechanisms already in place.

软的没边 2024-07-23 16:30:40

我同意,即使创建一个控制台可执行文件并安排它每分钟运行也是一种浪费精力。 我建议探索类似 Quartz.Net 的内容。 这样您就可以创建一个简单的作业并安排它每分钟运行一次。

I agree, it is kind of a waste of effort to create even a console executable and schedule it to be run every minute. I would suggest exploring something like Quartz.Net. That way you can create a simple job and schedule it to run every minute.

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