Results 1 to 4 of 4

Thread: Best way to launch a process at a specific time of day

  1. #1
    JTL
    JTL is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Jun 2014
    Posts
    2
    Reputation
    0

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

    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.

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,773
    Reputation
    1703
    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.

  3. #3
    JTL
    JTL is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Jun 2014
    Posts
    2
    Reputation
    0
    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.

  4. #4
    Herman is offline VB.NET Forum Idol
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2011
    Location
    Montreal, QC, CA
    Posts
    865
    Reputation
    1211
    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.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •