|
way to make a function execute at time 'x'
Is there a way to make a function's execution wait till a specific system time? example. I want the end user to choose from 3-4 times (time of day) to make a function run (shutdown or restart computer). The fourth choice maybe 1.5 hours from the time that the user would be prompted to make the choice. Is there a way to make the program check the current system time often enough to make the program execute properly, but not hog up a ton of CPU cycles?
The best solution I have come up with would be done by making the program sleep for approx. 30 seconds then run an IF statement to see if the user defined time = the current system time (+/- 30 sec) and loop until that value is reached.
Would this work sufficiently in your opinion, or is there another way? To my knowledge, Sleep uses little to no CPU time. If this is the case, then in theory, my example will use very little CPU resources while running the time check loop. So I guess my last question is. Can you actually designate a time and have the program reference that to the current system time then execute a function if the two are equal (in this case equal +/- 30 sec.)?
If I was not descriptive enough, please let me know and I will try and explain better.
Thanks for the help,
-BB98
__________________
Learning to use C++ and loving every minute of it.
|