调度控制台应用程序VS Windows服务?什么时候适合使用每个 [英] Scheduled console app vs Windows service? When is it appropriate to use each

查看:225
本文介绍了调度控制台应用程序VS Windows服务?什么时候适合使用每个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚看了这样的:<一href="http://stackoverflow.com/questions/442264/what-is-the-benefit-of-developing-the-application-as-a-windows-service">http://stackoverflow.com/questions/442264/what-is-the-benefit-of-developing-the-application-as-a-windows-service但我仍然不确定何时使用Windows服务的。

I just read this: http://stackoverflow.com/questions/442264/what-is-the-benefit-of-developing-the-application-as-a-windows-service but I'm still unsure of when to use a windows service.

予有需要被间隔(即每5分钟)运行几个任务。我应该使用哪种类型的项目?是否有应用程序的类型应该是Windows服务的任何例子吗?

I have a couple tasks that need to be run at intervals (i.e. every 5 minutes). Which project type should I use? Are there any examples of the types of applications that should be Windows services?

谢谢

凯尔

推荐答案

有关的任​​何计划的任务,我通常会推荐一个Windows服务,原因如下:

For any scheduled task, I would usually recommend a Windows Service, for the following reasons:

  • 在Windows服务运行,即使用户没有登录到PC(将运行,即使服务器坐在登录提示)(***注意 - 这可能取决于你的Windows正在运行的版本)
  • 系统服务可以运行的高权限的帐户,如网络服务和本地系统或用户 - 他们有更多的可配置性在这方面
  • 系统服务还内置于用于启动,停止,重新启动和暂停运行时的选项(有时)
  • 您还可以设置故障条件的服务,就像如果失败的话有它自动重新启动

据的,可以是窗口服务,很多时候他们的应用,如远程有用的应用其他的例子 - 你可以有一个服务运行一个远程服务器的客户端连接到。显然,对于要在后台运行,以及要在一定条件下发送电子邮件的数据处理任务,或进程非常有用的,等等。

As far as other examples of applications that can be windows services, a lot of times they are useful for applications such as remoting - you can have a service run a remoting server that clients connect to. Obviously very useful for data processing tasks that you want to run in the background as well, or processes where you want to send an email on certain conditions, etc.

在一般我总是发现计划任务,以更加脆弱和不可靠的。除非你让他们正确地记录,往往难以调试。

In general I've always found scheduled tasks to be much more fragile and unreliable. And unless you have them log properly, often harder to debug.

在提及与计时器错误 - 如果您阅读MS的网站上的错误报告,你可以看到它时,你所说的停止的Timer_Elapsed事件中造成的。这个问题的答案很简单 - 不叫停止。相反,裹在检查了整个事情的IsRunning布尔,只运行,如果IsRunning是假的。即使不是一个问题与定时,则需要在执行过程中呢,因为计时器会重新火做,如果你的执行需要更长的时间比你的时间间隔。

In reference to the bug with the Timer - if you read the bug report on MS's site, you can see that it is caused when you call "Stop" inside the Timer_Elapsed event. The answer to this is simple - don't call stop. Instead, wrap the whole thing in a check for a "IsRunning" boolean and only run if IsRunning is false. Even if there wasn't an issue with the timer, you need to do this anyway because the timer might re-fire during your execution if your execution takes longer than your timer interval.

不管怎样,我还是认为使用计划的任务是弱的解决方案,并给了我的Windows 95。

Anyway, I still think using scheduled tasks is a weak solution and gives me flashbacks of Windows 95.

这篇关于调度控制台应用程序VS Windows服务?什么时候适合使用每个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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