用于维护任务的 Windows 服务或任务计划程序? [英] Windows Service or Task Scheduler for maintenance tasks?

查看:30
本文介绍了用于维护任务的 Windows 服务或任务计划程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个执行一些维护任务的 C# 应用程序.它需要大约每小时运行一次,但如果它有点偏离并不太重要.它必须在没有人登录的 Win2003 服务器上运行.

I have a C# Application that does some maintenance tasks. It needs to run roughly every hour, although it's not too important if it's a bit off. And it has to run on a Win2003 Server with no one logged in.

基本上我想知道我是否应该编写一个 Windows 服务,如果是,Thread.Sleep() 是否是暂停线程一个小时的正确方法,或者是否有更好的方法来确保线程保持空闲状态并且不把任何服务器负载?(又名.自旋锁最相反的是什么)

Basically I wonder if I should write a Windows Service, and if yes, if Thread.Sleep() is a proper way to pause the Thread for an hour, or if there are better ways to make sure the Thread stays idle and does not put any server load? (aka. what is the most opposite of a Spinlock)

替代方案是 Windows 任务计划程序,但我不确定这是否适合服务器使用,因为 a) 我必须将计划存储在其中而不是我的 app.config 中,b) 我无法轻松控制服务通过启动/停止/重新启动和 c) 我不知道 Windows 用户的凭据是否与我在服务 MMC 管理单元中输入它时一样安全.

The alternative is the Windows Task Scheduler, but I am not sure if that is good for server use since a) i'd have to store the schedule in it rather than in my app.config, b) I cannot easily control the service through start/stop/restart and c) I do not know if the Credentials of the Windows User are as secure as when I enter it in the Service MMC Snapin.

你有什么看法?有一个空闲的服务是可能的还是好的,或者你会推荐任务调度程序吗?

What are your opinions? Is it possible and good to have an idle Service or would you recommend the task scheduler instead?

推荐答案

您可能会发现这个 视频 有趣.与负责 Windows 服务的工程师进行了良好的面试,并讨论了何时选择服务或任务.简而言之,如果您的功能属于定期维护类别,请执行任务.

You may find this video interesting . Good interview with the engineer responsible for windows services and also goes into when to pick service or task. In a nutshell if your feature falls into the periodic maintenance category go with a task.

这篇关于用于维护任务的 Windows 服务或任务计划程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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