简体   繁体   English

为备份程序实现调度程序

[英]Implementing a scheduler for a backup program

for a backup program I am doing I have already finished the GUI. 对于备份程序,我正在完成GUI。 Now I want to do the functional requirements. 现在我要做功能要求。 Each backup can have schedules. 每个备份可以有时间表。 There are predefined settings like every Sunday or Monday but the user can also specify his own schedules. 有一些预定义的设置,例如每个星期日或星期一,但用户也可以指定自己的时间表。

As I have never done anything like this, I was wondering what a good approach would be to running a backup every x hours or days. 由于我从来没有做过这样的事情,所以我想知道一种好的方法是每x个小时或几天运行一次备份。 I was thinking about using Threads or writing a service but both fields are totally new to me. 我当时正在考虑使用线程或编写服务,但是这两个领域对我来说都是全新的。 What would be the best method here? 最好的方法是什么?

If threaded development and service development are both totally new then I think you will struggle to implement this in a useful way. 如果线程开发和服务开发都是全新的,那么我认为您将很难以一种有用的方式来实现它。 Even so... 尽管如此...

Scheduler-type applications are best run as services, because otherwise you need the user to be logged in to be running the application. 调度程序类型的应用程序最好作为服务运行,因为否则您需要登录用户才能运行该应用程序。 Services run independently of the user being logged in. 服务独立于登录用户运行。

Because of this, however, services don't have a user interface so your GUI needs to package up the details of schedule into a configuration file somewhere, then signal the service to re-load that configuration file so that the service will then know what to do and when to do it. 因此,服务因此没有用户界面,因此您的GUI需要将日程表的详细信息打包到某个位置的配置文件中,然后向服务发出信号以重新加载该配置文件,以便该服务随后知道做和何时做。

The service will normally spawn a worker thread to do pretty much everything, and that worker thread needs to be able to respond to the service being shut down (read up on AutoResetEvent to see how this might be done across threads). 该服务通常会产生一个工作线程来完成几乎所有事情,并且该工作线程需要能够响应被关闭的服务(在AutoResetEvent上阅读以了解如何在线程之间完成此工作)。 The thread will then wait until either an event or for the appropriate time to arrive and then do whatever it has to do. 然后,线程将等待,直到某个事件或适当的时间到达,然后再执行其必须执行的操作。

None of this is actually complicated, but I suggest you do some digging into multithreaded programming first. 这实际上并不复杂,但是我建议您首先对多线程编程进行一些研究。

I agree with ColinM, Services are best for the Scheduler Type of application. 我同意ColinM的观点,服务最适合计划程序的应用程序类型。 You have to combine the Services with application to run your code at scheduled intervals. 您必须将服务与应用程序结合起来才能按计划的时间间隔运行代码。 See the article for more details - http://msdn.microsoft.com/en-us/magazine/cc163821.aspx 请参阅文章以了解更多详细信息-http://msdn.microsoft.com/zh-cn/magazine/cc163821.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM