gcue Posted April 28, 2009 Share Posted April 28, 2009 is there a way to cancel a function while its running? is there an easy way to do this? i would think you cant in autoit due to the inability to run multi-threads.. right? Link to comment Share on other sites More sharing options...
weaponx Posted April 28, 2009 Share Posted April 28, 2009 Return Link to comment Share on other sites More sharing options...
gcue Posted April 28, 2009 Author Share Posted April 28, 2009 so on an active process, a button is selectable? (with return as function behind it) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 28, 2009 Moderators Share Posted April 28, 2009 gcue,You could do this by using a HotKey to set a flag and then polling the flag in the function. Here is some proof-of-concept code:Global $fFlag = False HotKeySet("{ESC}", "Set_Flag") my_func() ConsoleWrite("Out" & @CRLF) Func my_func() ConsoleWrite("In" & @CRLF & $fFlag & @CRLF) While 1 If $fFlag Then Return Sleep(10) WEnd EndFunc Func Set_Flag() $fFlag = True ConsoleWrite($fFlag & @CRLF) EndFuncOf course, it is only useable if the function you wish to interrupt has suitable breaks to insert the If $fFlag lines, or has a nice useful loop in it. :-)I do not believe you can do it with a button, because the function called by the button will be queued until the running function ends - which is of no use. :-(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...
gcue Posted April 28, 2009 Author Share Posted April 28, 2009 that works well in a loop but what about other functions? prob no way huh? Link to comment Share on other sites More sharing options...
Skruge Posted April 28, 2009 Share Posted April 28, 2009 is there a way to cancel a function while its running? is there an easy way to do this? i would think you cant in autoit due to the inability to run multi-threads.. right? You can't do multiple threads, but you can do multiple processes, which would work for your situation.Script calls itself with a switch, new process runs your function, hotkey or other method kills the child process on demand. [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
gcue Posted January 5, 2012 Author Share Posted January 5, 2012 anyone have an example? Link to comment Share on other sites More sharing options...
guinness Posted January 5, 2012 Share Posted January 5, 2012 gcue, This thread is over 2 years old, surely you would've learnt something by now. Melba gave you an example, I suggest you try that. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted January 5, 2012 Share Posted January 5, 2012 anyone have an example?The wiki has. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 6, 2012 Moderators Share Posted January 6, 2012 gcue,This is the Interrupting a running function tutorial that I added to the Wiki since this thread was started. It should help you break into your function - it offers several ways to do it. 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...
gcue Posted January 11, 2012 Author Share Posted January 11, 2012 very interesting.. too bad only doable through hotkey =/ (when using onevent) thanks for creating the wikki entry melba =) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 11, 2012 Moderators Share Posted January 11, 2012 gcue,too bad only doable through hotkey(when using onevent)You obviously did not read the tutorial very thoroughly - it shows multiple ways to interrupt a function in both OnEvent and MessageLoop modes. If you cannot be bothered to read a tutorial which explains in detail how to use these different methods and shows examples of how to code them, why should we help you any further? 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...
gcue Posted January 11, 2012 Author Share Posted January 11, 2012 ahh sorry i misread it.. i thought the examples was a progression of the same example for each messageloop and onevent =) definitely makes sense now - ill try it out thanks!! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 11, 2012 Moderators Share Posted January 11, 2012 gcue, Please ask if you run into diffculties. 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...
gcue Posted January 17, 2012 Author Share Posted January 17, 2012 got it working on thanks again for the tutorial. the problem im coming across is that i have over 100 functions - my while loop is going to need that many if then or case statements along with that im gonna need that many extra variables.. *sigh* maybe theres a more code efficient way? expandcollapse popup#include <GUIConstantsEx.au3> ; Declare a flag Global $fRunOne = False Global $fRunTwo = False Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Test", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $cancel_button = GUICtrlCreateButton("CANCEL", 5, 5, 50, 20) GUICtrlSetOnEvent(-1, "CANCEL_FUNCS") $hButton_1 = GUICtrlCreateButton("Func One", 10, 50, 80, 30) GUICtrlSetOnEvent($hButton_1, "_Func_1") $hButton_2 = GUICtrlCreateButton("Func Two", 10, 90, 80, 30) GUICtrlSetOnEvent($hButton_2, "_Func_2") GUISetState() While 1 Sleep(10) ; Check if the flag has been set by the OnEvent function Select Case $fRunOne = True _Func_1_Run() Case $fRunTwo = True _Func_2_Run() EndSelect WEnd Func _Func_1() ; Set the flag within the OnEvent function $fRunOne = True EndFunc ;==>_Func_1 Func _Func_1_Run() For $i = 1 To 2000 ConsoleWrite($i & "-Func 1 Running" & @CRLF) Sleep(100) if $fRunOne = False Then ExitLoop EndIf Next EndFunc ;==>_Func_1_Run Func _Func_2() ; Set the flag within the OnEvent function $fRunTwo = True EndFunc ;==>_Func_1 Func _Func_2_Run() For $i = 1 To 2000 ConsoleWrite($i & "-Func 2 Running" & @CRLF) Sleep(100) if $fRunTwo = False Then ExitLoop EndIf Next EndFunc ;==>_Func_2 Func CANCEL_FUNCS() ConsoleWrite("CANCELED" & @CRLF) $fRunOne = False $fRunTwo = False EndFunc Func _Exit() Exit EndFunc ;==>_Exit Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 17, 2012 Moderators Share Posted January 17, 2012 gcue,The first question to ask is if you will need to interrupt all of the functions? Many of the functions in my scripts are simple helper functions which complete very quickly - only a few tend to last long enough to cause a serious delay in script response.The second point is that you have chosen the "simple" way to interrupt in OnEvent mode - which has the disadvantage of needing you to poll the flags in the While...WEnd loop. Lower down in the tutorial is another OnEvent script which shows you how to interrupt functions directly - with either a HotKey, an Accelerator key or a control. If you were to use one of those methods then your problem vanishes entirely. Let me know if you need any more advice - always happy to help out. 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...
gcue Posted January 17, 2012 Author Share Posted January 17, 2012 (edited) yes will need to interrupt most of them unfortunately. yea i saw the hotkey way - sometimes thats hard to communicate as a way of canceling - i have a large user base that uses the tool - i can try to put the note "KEY to cancel" in a noticeable place and see how that goes =) thanks again for the awesome wiki entry. your help is VERY much appreciated here Melba! Edited January 17, 2012 by gcue Link to comment Share on other sites More sharing options...
gcue Posted March 14, 2012 Author Share Posted March 14, 2012 hey Melba, So I went with the hotkey method works great! thanks again for your help. Only Problem is that the hotkey applies even when my gui isnt being selected so it might conflict with another program. Sure I can set something like CTRL+ATL+SHIFT+P which probably won't get used by anything else. however hard to remember weird combination of keys like that. I am trying to use it to cancel a running process so ESC would be ideal but then ESC wont work in other programs. ive also tried setting the hotkey through GUISetAccelerators but that wont interrupt a running process. any ideas? thanks in advance Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 14, 2012 Moderators Share Posted March 14, 2012 gcue,ive also tried setting the hotkey through GUISetAccelerators but that wont interrupt a running processYes it will - go and read the tutorial again. 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