Likurg Posted February 10, 2010 Share Posted February 10, 2010 Hi! I have a problem writting GUI application: gui has a button, and after clicking at that button application performs a time consuming operation. I would like to give a possibility to user to cancel this operation ( and close AutoIt application ). I know, that gui events are in queue and processed in order, so is it possible to put this time consuming operation in another thread? Here is code: ; GUI Creation $gui = GuiCreate("What to build?",220,100) Opt("GUIOnEventMode", 1) ; Combo Box Creation $comboboxFramework = GuiCtrlCreateCombo($arr[UBound($arr) - 1],10,10,160,20) For $i = UBound($arr) - 2 to 0 GuiCtrlSetData($comboboxFramework,$arr[$i]) Next $combobox = GuiCtrlCreateCombo("NarTest 3.6",10,40,160,20) ; Combo Box Creation GuiCtrlSetData($combobox,"NarTest 3.5|Isp 3.6|Isp 3.5|All") ; Button Creation $button = GuiCtrlCreateButton("Build",10,70,60,20) GUICtrlSetOnEvent($button, "BuildClicked") ;$progress = GUICtrlCreateProgress(10,100,200,25) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, "CloseClicked") Func CloseClicked() Exit EndFunc Func BuildClicked() ;time consuming operation EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 10, 2010 Moderators Share Posted February 10, 2010 Likurg,Welcome to the AutoIt forum. The short answer to the question in your title is - NO, AutoIt does not do multi-threading.However, there are some possible work arounds - here are 2 that I have used:1. Use a HotKey to break in and exit (from the Help file: "A hotkey-press *typically* interrupts the active AutoIt function/statement and runs its user function until it completes or is interrupted")HotKeySet("{ESC}", "On_Exit") #include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) $hButton = GUICtrlCreateButton("Long Func", 10, 10, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton Long() EndSwitch WEnd Func Long() ConsoleWrite("Starting Infinite Loop" & @CRLF) ; Is infinity long enough While 1 Sleep(10) WEnd ConsoleWrite("Ending Infinite Loop" & @CRLF) ; Will we ever get here? EndFunc Func On_Exit() Exit EndFunc2. Put the long process into another compiled exe which you can run from within your GUI script. Then use ProcessClose to kill it if your main GUI is closed. There are many ways to pass and read parameters between AutoIt scripts - but in this case the command line would probably be your best bet. Look in the Help file under <Using Autoit - Command Line Parameters>. I would go this way personally.I hope this helps. You know where we are if you want some more hints! 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...
Likurg Posted February 10, 2010 Author Share Posted February 10, 2010 Big Thanks! Hotkey works 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