Way to execute a .Net application on specific days
I have a requirement where an application which is run by windows service to be ex开发者_如何学编程ecuted on specific days in a week(Sunday through Saturday). These days should be stored in a config file and can be changed by user at any time.
Can you please point to right direction in achieving this. Please let me know if you need any clarification on this.
I'd suggest using Windows Task Scheduler instead of a service to launch the application. It is designed for this scenario.
If You are in Windows environment, then you can use Windows Task Scheduler.
The following is for Windows XP, but the instructions are almost the same for other versions of Windows
http://support.microsoft.com/kb/308569
Simple. Windows Operating System TASK SCHEDULER. Start your application at specific days. Finished.
How about registering them to the scheduled tasks?
It already has a great interface and any user can deal with them, let alone your costumer's IT depeartment.
You can also create a tool that registers the scheduled task to windows with parameters according to the XML file.
I agree with all the above. Windows Task Scheduler would be the best and easiest solution.
You could even write a console application and set it to run at given times.
Here is a small guide to console applications for scheduled tasks:
http://www.15seconds.com/issue/080508.htm
As everyone has answered, Windows Scheduler is already part of Windows and will do this for you. However, if you need a programmatic answer to this, you can use the following C# code:
// Read in your configuration file
// and I am assuming you are reading in the file and storing the
// Days of the week you need it to run in a string array
foreach (string DayToRun in MyStringArray)
{
if (DateTime.Now.DayOfWeek.ToString().ToUpper().Equals(DayToRun.ToUpper())
{
// Today is the day we need to execute.
// Do execution here
System.Diagnostics.Process.Start("C:\\MyProgramToExecute.EXE");
break;
}
}
精彩评论