How to Run a Windows Service at specific time each day
Solution 1
I would recommend changing your approach. Services are normally used for long running processes that are always running. For processes that run on a schedule, windows has a built in component called "Task Scheduler" that is designed for running applications on a schedule.
You can simply take your application service code and paste it into a windows console application and then schedule the resultant exe to run on whatever schedule you see fit by using the Windows Task Scheduler.
Hope this helps.
Solution 2
The best option is to use Quartz schedular in windows service. Using quartz you can also schedule multiple jobs in a single service based on time for execution like daily on 5 A.M. , every hour, every minute, weekly etc. It is too flexible to use.
Pranav
Updated on June 29, 2022Comments
-
Pranav almost 2 years
I have a windows service that i need to run at specific time of day.Suppose the time id 11:00 PM.At present i have code to run this service on everyday but how to add time variant into this i am not able to get that. Here is my code in c#..
protected override void OnStart(string[] args) { timer = new Timer(); timer.Interval = 1000 * 60 * 60 * 24;//set interval of one day timer.Elapsed += new ElapsedEventHandler(timer_Elapsed); start_timer(); } static void timer_Elapsed(object sender, ElapsedEventArgs e) { // Add your code here readDataFromAd(); } private static void start_timer() { timer.Start(); }
Please help me in defining the time also along with the interval.The time Should be 11:00 PM and the timer should execute the Method Everyday.
-
cnd about 10 yearsAgreed, in addition there is windows scheduler