If you want the task to run at regular intervals rather than constantly, you should study the Task Scheduler .
If you need your code for maintenance, but for βactivatingβ every hour, the easiest approach is to make your service a COM object and do a simple task every hour that calls jscript / vbscript, which creates your COM object and calls a simple method on it .
An alternative is to use any of the pending APIs to βwasteβ hours without using cycles.
Please note that you also need to consider some interesting design decisions that depend on your scenario:
- How will your service start if it works or stops by the user?
- if you start after more than an hour, do you have to start again or do you need to wait to get the exact hourly schedule?
- How do you track the latest activation time if the time zone or daylight saving time changed when you were not active?
- Does your service not allow your computer to go to sleep / idle mode or when the laptop cover is closed? if not, do you need to wake up the computer in an hour to make your service work with your schedule?
Some of them take care of the task scheduler, so I highly recommend taking this route against waiting an hour in your code.
Franci penov
source share