编写计划Windows服务在.NET计划、Windows、NET

2023-09-03 21:31:27 作者:ζ奇葩朵朵开り

我想写一个窗口服务,用户可以安排。也就是说,用户可以选择从上午9:00日常运行服务到下午6点,或者他可以运行它每天晚上,从晚上12点开始,晚上到第二天早上6等有没有出箱.NET API,这将帮助我做到这一点?我知道我可以使用计划任务做到这一点,但有什么办法做到这一点编程?

I want to write a windows service which the user can schedule. i.e, the user can choose to run the service from 9:00 AM to 6 PM daily, or he could run it every night, starting from night 12 o clock at night to next day morning 6, etc. Is there any out of the box .NET API that will help me do this? I know I can do this using the Scheduled tasks, but is there any way to do this programmatically?

推荐答案

我的第一反应是质疑为什么服务?但更重要的是,问题是,为什么不使用由操作系统提供了强大的调度?

My first response is to question why a service? But more importantly, the question would be why not use the powerful scheduler that is provided by the operating system?

这是说,一个窗口服务为pretty的简单,只是你的应用程序在运行一个线程,你可以在两部分出货,第一个是执行一个计时器服务本身。该服务的启动可以检查注册表值,以确定多久它应该执行。

That said, a windows service is pretty much just a thread that your application runs in. You could ship it in two parts, the first is the service itself which executes on a timer. The startup of the service could check a registry value to determine how often it's supposed to execute.

该服务的第二部分将是一个小窗口的应用程序,允许用户设置日程安排,和,当然,把它写pviously提到的注册表值$ P $。

The second part of the service would be a little windows app that allowed the user to set the schedule, and, of course, write it to the previously mentioned registry value.

没有任何形式的特殊的API,你需要。

There isn't any sort of special API that you'd need.