Windows任务调度程序如何可靠地调度代码重复运行?

时间:2021-09-08 05:43:04

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

我有一些代码需要坐在Windows Server 2003机器上并且每分钟运行一次。

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?

推荐的处理方法是什么?是否可以将其设计为控制台服务,让任务调度程序只需要一分钟就能完成它? (这是可能的吗?)我应该把它搞砸并写成Windows服务吗?

8 个解决方案

#1


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.

由于它需要每分钟运行一次,我建议编写一个Windows服务。它并不是很复杂,如果你以前从未这样做过,那么了解它是如何完成的将是很好的。

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

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

#2


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.

我会说它搞砸了,把它写成Windows服务。我没有发现计划任务非常可靠,当它没有运行时,我还没有找到一个简单的方法来找出它没有的原因。

#3


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

Windows计划任务对于我们的目的而言相当可靠,并且由于其易于安装和高级恢复功能,我们几乎在所有情况下都支持Windows服务。如果写入的代码的一部分最终被锁定或在一段不应该存在的代码中循环,那么Windows服务的永远性质可能最终成为一个问题。我们通常在一个代码中编写代码时尚与此类似

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.

然后,作为计划任务的一部分,我们对进程运行的时间设置了时间限制,如果进程运行的时间过长,则会终止进程。如果我们确实有一段代码遇到问题,则Scheduled Tasks会终止它,并且该过程将在下一分钟启动。

#4


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.

如果你需要让它每分钟运行一次,我会把它建成一个Windows服务。我不会将调度程序用于少于日常任务的任何事情。

#5


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.

如果你把它写成一个Windows服务,那么只有少一个地方可以检查,以防出现问题。

#6


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

在搜索预定的服务帮助时,我看到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.

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

#7


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.

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

#8


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.

我同意,创建一个控制台可执行文件并安排它每分钟运行是一种浪费。我建议探索像Quartz.Net这样的东西。这样你就可以创建一个简单的工作并安排它每分钟运行一次。

#1


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.

由于它需要每分钟运行一次,我建议编写一个Windows服务。它并不是很复杂,如果你以前从未这样做过,那么了解它是如何完成的将是很好的。

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

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

#2


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.

我会说它搞砸了,把它写成Windows服务。我没有发现计划任务非常可靠,当它没有运行时,我还没有找到一个简单的方法来找出它没有的原因。

#3


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

Windows计划任务对于我们的目的而言相当可靠,并且由于其易于安装和高级恢复功能,我们几乎在所有情况下都支持Windows服务。如果写入的代码的一部分最终被锁定或在一段不应该存在的代码中循环,那么Windows服务的永远性质可能最终成为一个问题。我们通常在一个代码中编写代码时尚与此类似

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.

然后,作为计划任务的一部分,我们对进程运行的时间设置了时间限制,如果进程运行的时间过长,则会终止进程。如果我们确实有一段代码遇到问题,则Scheduled Tasks会终止它,并且该过程将在下一分钟启动。

#4


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.

如果你需要让它每分钟运行一次,我会把它建成一个Windows服务。我不会将调度程序用于少于日常任务的任何事情。

#5


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.

如果你把它写成一个Windows服务,那么只有少一个地方可以检查,以防出现问题。

#6


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

在搜索预定的服务帮助时,我看到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.

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

#7


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.

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

#8


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.

我同意,创建一个控制台可执行文件并安排它每分钟运行是一种浪费。我建议探索像Quartz.Net这样的东西。这样你就可以创建一个简单的工作并安排它每分钟运行一次。