当前位置: 动力学知识库 > 问答 > 编程问答 >

c# schedule windows service for specific date(s)

问题描述:

I have seen a lot of posts to configure a windows service for daily/weekly etc schedules, but if I want a schedule that is not uniform, how do I manage that from a windows-service perspective? I have an app that I want to run at particular times. Running it at a uniform schedule wouldn't do me any good and just waste resources. Can I configure it by using some XML file, or windows service configuration?

网友答案:

You have three options.

  1. Take a look at Quartz.net

  2. Use Windows scheduler. Just have a different "schedule" for each date/time you need the app to run.

  3. Write your own.

网友答案:

Here's one way to do it that is something of a hybrid approach:

Create a text file that has the dates and times you want the program to run. For example, it might contain:

2011-03-01
0100
0312
0815
0945
1340

2011-03-02
0220
...

Then, write your program that does whatever task it needs to do, and the last thing it does before exiting is read the file, find the next time that it needs to run, and schedules itself (by issuing an AT command, by calling schtasks.exe, or by calling the equivalent Task Scheduler API functions).

The Task Scheduler API is not for the timid. I would suggest looking into a wrapper. A search for "windows task scheduler C#" returns several.

分享给朋友:
您可能感兴趣的文章:
随机阅读: