Jump to content
Sign in to follow this  
Freedom1

App sleeps until a specific time....

Recommended Posts

Freedom1

Hello,

I want to write a small app that starts up when the PC is started and waits till a specific time to continue with execution of code. Lets say the PC is turned on at 8am and my app starts and runs in the background. It waits until 4pm and then starts to perform it functions.

I know I could use XP scheduler but I'd like to have it all in AutoIt.

I dont want to burn up bunches of CPU cycles while waiting. How do I code it?

Thanks,

Freedom1

If you want to see my entire task look at it here: http://www.autoitscript.com/forum/index.ph...c=82512&hl=

Share this post


Link to post
Share on other sites
oMBRa

something like:

While @HOUR < 16
   Sleep(100)
Wend

Share this post


Link to post
Share on other sites
Richard Robertson

You could probably even change that Sleep to something large like 5 minutes.

Share this post


Link to post
Share on other sites
Freedom1

You could probably even change that Sleep to something large like 5 minutes.

Thank you oMBra and Richard for your suggestion. I should have tried it first. For some reason I thought "Sleep" would use a lot of cycles like a tight loop. After viewing the performance panel of the task manager I see that it uses very few cycles. AutoIt is a winner. As for the code, I'm thinking:

; Calculate time in milliseconds between now and wakeup time

; sleep(Calculated Milliseconds)

; Continue onward with rest of script

Is there any problem with sleeping a large calculated-millisecond value? Say the wakeup time is 4pm and the current time is 6pm the calculated milliseconds would be 22 * 3,600,000 = Sleep(79,200,000)

Thanks alot,

Freedom1

Share this post


Link to post
Share on other sites
dbzfanatic

That should be fine as long as you don't have the commas in it. If you wanted to be absolutely sure you could do something like

$time = _DateDiff("s",_NowCalc(),*end time*);return in seconds the difference
Sleep(Number($time * 1000));calculate ms difference and sleep.
;rest of code

Share this post


Link to post
Share on other sites
Richard Robertson

Using sleep will drastically reduce CPU cycles because sleep causes the thread to cease doing anything until the time has expired.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×