lark Posted January 16, 2012 Posted January 16, 2012 (edited) Hi all, My first uploaded UDF So this is just an improvised version of the Sleep function. It allows the script to sleep, as normal, while still running code. This would be useful if you want your script to sleep for a long period of time, but for your GUI to still be fully functional. So, if you have your script sleep for 5 minutes, and want your GUI to close when you click on the close button, then this will allow you to do it. I've included the basic switch for the GuiGetMsg() function with the $GUI_EVENT_CLOSE in it, but left everything else out, so that you can customize and edit it to fit your needs. It takes two parameters: The first one is how long it should wait, in milliseconds, just like the regular sleep function. The second parameter is optional (has a default at 10), and is for how long it should pause while running through its while loop. Here it is: Func Sleep2($waitTime, $pauseTime = 10) Local $finishTime = $waitTime + (@YDAY * 86400000) + (@HOUR * 3600000) + (@MIN * 60000) + (@SEC * 1000) + @MSEC While 1 Local $currentTime = (@YDAY * 86400000) + (@HOUR * 3600000) + (@MIN * 60000) + (@SEC * 1000) + @MSEC If $currentTime >= $finishTime Then ExitLoop $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch Sleep($pauseTime) WEnd EndFunc If you want to test it, run this code- it shows a tooltip displaying the current milisecond we are at in the year, then pauses for 5 seconds, and displays the new current time right below it. $time = (@YDAY * 86400000) + (@HOUR * 3600000) + (@MIN * 60000) + (@SEC * 1000) + @MSEC ToolTip($time) Sleep2(5000) ToolTip($time & @CRLF & ((@YDAY * 86400000) + (@HOUR * 3600000) + (@MIN * 60000) + (@SEC * 1000) + @MSEC)) While 1 Sleep(30) WEnd Tell me what you think. If you want to download it as a file, here it is: Edited January 23, 2012 by mischieftoo
GicuPiticu Posted February 26, 2012 Posted February 26, 2012 (edited) OK, 2 things at first sight: 1. While executing Sleep($pauseTime) your script won't respond to any events. 2. Why not use TimerInit() and TimerDiff().... they are much cheaper as per CPU used. Edited February 26, 2012 by GicuPiticu
Moderators Melba23 Posted February 26, 2012 Moderators Posted February 26, 2012 mischieftoo,In fact you do not need a Sleep($pauseTime) in there at all. GUIGetMsg idles the CPU for you - around 12ms if the CPU is busy, much shorter but still long enough if the CPU is idle. So all you are doing with your additional Sleep is making the script slightly less responsive - which is not what you want. And I would definitely look at using TimerInit() and TimerDiff() to check for $waitTime - they are much more efficient that the complex $finishTime/$currentTime calculations you use at the moment. 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
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