Jump to content

GUI events - multi threaded


Likurg
 Share

Recommended Posts

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

  • Moderators

Likurg,

Welcome to the AutoIt forum. :D

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
EndFunc

2. 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! :huggles:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...