需要帮助编写循环任务调度程序
我需要编写一个工具,它将按照用户可配置的时间表运行重复任务。我将用 C# 3.5 编写它,它将在 XP、Windows 7 或 Windows Server 2008 上运行。完成任务大约需要 20 分钟。用户可能想要设置多种配置:例如每日、每周和每月周期。使用任务计划程序不是一个选项。
用户将通过类似于 Outlook 的定期约会对话框的界面来安排重复。一旦他们设置了时间表,他们就会启动它,它应该位于系统托盘中并在指定时间启动其任务,然后发送邮件以表明它已完成。
编写此代码的最佳方法是什么,以免耗尽资源、锁定主机或出现其他行为不当?
I need to write a tool that will run a recurring task on a user configurable schedule. I'll write it in C# 3.5 and it will run on XP, Windows 7, or Windows Server 2008. The tasks take about 20 minutes to complete. The users will probably want to set up several configurations: e.g, daily, weekly, and monthly cycles. Using Task Scheduler is not an option.
The user will schedule recurrences through an interface similar to Outlook's recurring appointment dialog. Once they set up the schedule they will start it up and it should sit in the system tray and kick off its tasks at the appointed times, then send mail to indicate it has finished.
What is the best way to write this so that it doesn't eat up resources, lock up the host, or otherwise misbehave?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您能做的最好的事情就是利用操作系统提供的功能来避免重新发明轮子。请参阅文章 从托管代码调用 Windows Vista(和 Windows Server 2008)中的任务计划程序 来自 Bart De Smet,用于非常中肯的用法来自 C# 的 Windows 任务调度程序。
如果由于某种原因您必须实现自己的服务(例如,更好地控制依赖项),我会查看一些 .NET 兼容语言的开源 Cron 实现。有一篇关于代码项目的代码文章,名为 用 C# 实现小型 Cron 服务这似乎是这样做的。基于他的文章基于事件的 Cron (预定)工作 在 C# 中,Bob Cravens 似乎在该领域做了一些更彻底的工作,或者至少更彻底地记录了他的工作。如果你环顾四周,我确信还有其他的,基于 Cron 的东西是一个很好的起点。
The best thing you can do is avoid reinventing the wheel by leveraging what the OS provides. See the article Calling the Task Scheduler in Windows Vista (and Windows Server 2008) from managed code from Bart De Smet for a very to-the-point usage of the windows task scheduler from C#.
If for some reason you must implement your own service (e.g. greater control over dependencies), I'd look at some of the open source Cron implementations in .NET compatible languages. There is an article with code on code project named Implementing a small Cron service in C# that seems to do this. Based on his article An Event Based Cron (Scheduled) Job In C#, it looks like Bob Cravens has done some more thorough work in this area or at least documented his work more thoroughly. I'm sure there are others if you look around, and something based on Cron is a good starting point.
我建议编写一个使用 SQlite 数据库来获取时间表的 Windows 服务
添加一个 GUI 来将您需要的任何内容写入数据库,但请记住使用
而不是
在您的 Windows 服务中
I will suggest writing a Windows Service that uses a SQlite db to get the schedules and
add a GUI to write whatever you need to the db but remember to use
and not the
In your Windows Service