mmoalem Posted April 15, 2016 Share Posted April 15, 2016 Hi there all - another day another question SO I have a set of commands in the script which I want to run in 25 hours interval and I am finding it tricky... At the end of the script I have a Sleep command for the remaining of the time to the 25 hours endline - I am trying to work out how to read the date/time at the beginning of the script than at the end calculate how much time passed and add whatever amount of seconds needed to sllep for the 25 hours to pass... please if you can point me in the direction... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 15, 2016 Moderators Share Posted April 15, 2016 mmoalem, I would not use Sleep at all. I would run _NowCalc as the task begins and then use _DateDiff to get a value for the next run time. Then run a check in the idle loop which gets the _NowCalc value at regular intervals (depending on the accuracy you require) until it matches the required value. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
mmoalem Posted April 15, 2016 Author Share Posted April 15, 2016 Thanks for the help Melba! your suggestion does the job perfectly but I'm courious why not Sleep? Accuracy is not important in this case and I use the Sleep to have a visual countdown on ToolTip to know how long till it starts again... so thats what I came up with is: While 1 $startRunTime = _NowCalc() ; script goes here.... $SecondsPassed = _DateDiff('s', $startTimer, _NowCalc()) $MilliSecondsLeftTo25hrs = 90000000-$SecondsPassed*1000 Sleep ($MilliSecondsLeftTo25hrs) WEnd Does it look right? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 15, 2016 Moderators Share Posted April 15, 2016 mmoalem, You could make it a little bit simpler: While 1 $nBegin = TimerInit() ; script goes here.... $MilliSecondsLeftTo25hrs = 25 * 60 * 60 * 1000 - Int(TimerDiff($nBegin)) Sleep($MilliSecondsLeftTo25hrs) WEnd M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
mmoalem Posted April 15, 2016 Author Share Posted April 15, 2016 Thanks Melba23 for the script, I was just wondering about the resources use under the two different scripts - if i understand right a timer will be consuming cpu cycles throughout the script run while the nowcalc method will only use cpu cycles on fetching the time... probably very little difference in real terms but wondered if it is the most efficient way... I am a complete beginner so please forgive me if it is stupid concern... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 16, 2016 Moderators Share Posted April 16, 2016 mmoalem, I have several compiled AutoIt executables running permanently - as long as you put a Sleep(10) in any loops (remember that GUIGetMsg does that for you automatically) they do not seem to interfere in the smooth running of my machine. I believe that you are worrying unnecessarily. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now