Question Best way to launch a process at a specific time of day

JTL

New member
Joined
Jun 28, 2014
Messages
2
Programming Experience
5-10
I am replacing a program I wrote several years ago. I start my program when the computer boots. It then waits until 3:00 in the morning to launch an other application that retrives text data from our cash registers with the prior days results. I used a timer to check the system time every 30 seconds and check it for the 3:00 am time. When the time is met, I launch the other application and use the WaitForSingle Process to let me know when it is finished and I can process the text files. I know I can now use the Process object without messing with the API. My question is about the timer that waits until 3:00 am. I have read on this forum that watching the system is not the best. Can you think of a more elegant way to wait to launch? My old program had a drop down list that would allow the user to set the launch time after the original form is displayed.
 
You can tell the Timer to Tick whenever you want. It only needs to Tick once, at the time you want to start the process. The Interval determines when the Timer Ticks so set the Interval appropriately so that the Tick event is raised at 3.00 AM. You know the date and time when you want the Timer to Tick and you know the current date and time so simply subtract one from the other to get the number of milliseconds for the Timer Interval.
 
Thanks for the idea. I will set up a system to determine the milliseconds until the time selected by the user. I will also simply add a "Launch Now" button if I want to launch the application myself.

By the way thanks for your blog about using parameters to create the sql string when inserting records into Access database. I found my date/time information worked much better with parameters rather than using stringbuilder to create the commandtext.
 
Hmmm.. There is already an entire facility for this in Windows. It's called the Windows Task Scheduler (look in the Administrative Tools panel...). Instead of starting your app to wait around until 3:00, just start it at 3:00 and do what you need to do.
 
Back
Top