ok123jump Posted May 30, 2010 Share Posted May 30, 2010 (edited) Hi guys, I have a program that is controlled through a GUI. The bottom of my GUI has a clock which is updated every 50ms during the While 1 loop. Some of the GUI buttons call functions which contain algorithms that take on the order of 10's of minutes to run. During the running of these functions, the clock does not update. I am looking for a way to force the clock to update every 20ms - regardless of whether or not there is another loop running within the program. In essence, it would run in the background all the time. Here's a bit of my code to show you how I'm currently animating the clock. ;----------------GUI Functionality Code------------------- While 1 ;20ms Delay to Reduce CPU Usage Sleep(20) ;Get and Read Time UpdateTime() $nMsg = GUIGetMsg() Switch $nMsg Case $Button_ExportData AutoItSetOption("MouseCoordMode", 0) ExportData() $regionFlag1 = False $regionFlag2 = False Case . . . . . . Case $Menu_Tools_CoordTool Local $scrDir = @ScriptDir Run("Coordinate Tool.exe", $scrDir & "\Tools") EndSwitch WEnd . . . . . . Func UpdateTime() $tCur = _Date_Time_GetLocalTime() GUICtrlSetData($Label_Clock, _Date_Time_SystemTimeToTimeStr($tCur)) EndFunc I guess this fits into my more general question about how I would have a separate monitoring layer that would allow the program to be terminated by simply clicking the "x" button during algorithm execution, but I fear the flames. =/ Thanks for the help! Edited May 30, 2010 by ok123jump Link to comment Share on other sites More sharing options...
zeffy Posted May 30, 2010 Share Posted May 30, 2010 (edited) One way to do this would be to have your app invoke it's self with a command line parameter that updates the parent process's GUI. Example If $CmdLine[0] Then If $CmdLine[1] = "/time" Then $hTimeControl = ControlGetHandle("Your app's title", "", 999) ; Replace 999 with whatever the Time Update's ControlID is While 1 ControlSetText("Your app's title", "", $hTimeControl, @HOUR & ":" & @MIN & ":" & @SEC & "." & @MSEC) Sleep(20) WEnd EndIf EndIf Edited May 30, 2010 by Zef Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 30, 2010 Moderators Share Posted May 30, 2010 ok123jump,For the clock update, try using AdlibRegister. It runs a function at a predetermined interval regardless of what else is happening in your script. As for the exit problem, if you use the search feature this has been answered many times before. A lot depends on whether you are using OnEvent or MessageLoop mode. 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...
soadmania Posted May 30, 2010 Share Posted May 30, 2010 You can use timers also. Link to comment Share on other sites More sharing options...
ok123jump Posted May 30, 2010 Author Share Posted May 30, 2010 (edited) ok123jump,For the clock update, try using AdlibRegister. It runs a function at a predetermined interval regardless of what else is happening in your script. As for the exit problem, if you use the search feature this has been answered many times before. A lot depends on whether you are using OnEvent or MessageLoop mode. M23Thanks! The AdlibRegister function worked! I have been so bothered by fixing this problem that I have spent so much time trying to structure my code so that the GUI functions operated independently of the main calculation loop - I thought I would need to run the Clock in the GUI functions segment.This simplifies the problem very much so!Oh yeah... thnx for the flames! I searched under the parameters "run simultaneously", "execute simultaneously", "in parllel", "calculate parallel", "run at the same time"... and about two dozen other terms. You can complain about the quality of my choice for search terms, but not of my non-use of the search function. I am using a MessageLoop, I believe. Edited May 30, 2010 by ok123jump Link to comment Share on other sites More sharing options...
GEOSoft Posted May 30, 2010 Share Posted May 30, 2010 Thanks! The AdlibRegister function worked! I have been so bothered by fixing this problem that I have spent so much time trying to structure my code so that the GUI functions operated independently of the main calculation loop - I thought I would need to run the Clock in the GUI functions segment.This simplifies the problem very much so!Oh yeah... thnx for the flames! I searched under the parameters "run simultaneously", "execute simultaneously", "in parllel", "calculate parallel", "run at the same time"... and about two dozen other terms. You can complain about the quality of my choice for search terms, but not of my non-use of the search function. I am using a MessageLoop, I believe.I don't see where Melba23 flamed you at all in this thread and this is the second time in the thread you have refered to being flamed. Perhaps you would like to provide a link to a post where you were flamed. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
ok123jump Posted May 30, 2010 Author Share Posted May 30, 2010 Mmmm... perhaps "flamed" was not the right word. How about "accosted"? I was accosted by Melba23 for failing to use the search functionality - when in fact, I had. That just doesn't roll off your tongue like "flamed". Link to comment Share on other sites More sharing options...
GEOSoft Posted May 30, 2010 Share Posted May 30, 2010 I can only see where he suggested the use of the Search feature and I can't see that as accosting you. We are well aware that Search can be tricky and the search terms can be very critical. He suggested that as a way for you to find an answer and that should not be misconstrued into meaning anything else.Perhaps you think that he should have done the search for you? That does happen on occasion but only if the person making the reply has the time to do it for you and generally you only get one chance in that direction. The next time you want help searching, it just won't happen so don't waste your one shot. We all had to get used to the search at one point and it still annoys me but the more you use it the better you become at it. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 30, 2010 Moderators Share Posted May 30, 2010 ok123jump,Please try not to be so sensitive - if you think that was "flaming" you must have a really difficult time using any forum! George is quite correct - I was merely suggesting that you search to find how to use the [X] in a function. And I am well aware that Search is tricky - my top tip is to use "+" in front of each multiple term. Just to prove what nice people we are, here is the content of a post I wrote a few days ago answering the same question:[previous post]If you use OnEvent mode, you can break into the running function:#include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Test", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUISetState() _Long_Function() ; Enter an infinite loop While 1 Sleep(10) WEnd Func _Long_Function() $iBegin = TimerInit() While TimerDiff($iBegin) < 10000 ConsoleWrite(@SEC & @CRLF) Sleep(1000) WEnd EndFunc Func CLOSEClicked() Exit EndFunc If you use MessageLoop mode, you have a big problem. AutoIt will NOT interrupt a running function unless you use a HotKey. So if you have long function without a periodic check of some kind, you cannot break out. The best you can do is run a HotKey and set a flag which you check now and again with an Adlib function. [/previous post]I also notice that I neglected to welcome you to the forum as I normally do with newcomers - my apologies: Welcome to the AutoIt forum. Are we all friends again now? 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...
ok123jump Posted May 30, 2010 Author Share Posted May 30, 2010 I also notice that I neglected to welcome you to the forum as I normally do with newcomers - my apologies: Welcome to the AutoIt forum. Are we all friends again now? M23Of course we're all friends. I posted the "flaming" comment mostly joking, but I see that's a serious accusation here. =/I do appreciate your help. I am going to study your code and attempt to integrate the strategy into my program.A further question on the AdlibRegister functionality.I implemented it, it works great until one of my routines gets in to some pixel checksum subroutines. When this occurs, AutoIt seems to crash. Have you heard of this, or might it be some other problem? When I disable the pixel checksum routines, my script seems to behave just fine. Link to comment Share on other sites More sharing options...
martin Posted May 30, 2010 Share Posted May 30, 2010 Note that AdlibRegister will not always interrupt a script and update the clock or whatever. For example, dragging the window might make the clock freeze using AdlibRegister. Using timers is more reliable I think. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Yashied Posted May 30, 2010 Share Posted May 30, 2010 (edited) For example, dragging the window might make the clock freeze using AdlibRegister.Or MsgBox(), or context menu. _Timer_SetTimer() will be the best choice, but Timers out of competition. Edited May 30, 2010 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... 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