VVvKamper Posted October 20, 2013 Share Posted October 20, 2013 I'm trying to interrupt the running function as well as in http://www.autoitscript.com/wiki/Interrupting_a_running_function but using TrayItemSetOnEvent instead of GUICtrlSetOnEvent. The problem is that this code does not work and i cant figure out why. #NoTrayIcon Opt("TrayMenuMode", 1) Opt("TrayOnEventMode", 1) TrayCreateItem("Start") TrayItemSetOnEvent(-1, "Start") TrayCreateItem("Stop") TrayItemSetOnEvent(-1, "Stop") Global $f=1 TraySetState() While 1 Sleep (50) WEnd Func Start() While 1 If $f = 0 Then ExitLoop EndIf MsgBox(64,"f", $f) WEnd MsgBox(64, "hi", "stop") Exit EndFunc Func Stop() $f = 0 EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 20, 2013 Moderators Share Posted October 20, 2013 VVvKamper,Here is one way to do it:expandcollapse popup#include <GUIConstantsEx.au3> Opt("TrayMenuMode", 1) Opt("TrayOnEventMode", 1) $cStart = TrayCreateItem("Start") TrayItemSetOnEvent(-1, "Start") $cStop = TrayCreateItem("Stop") TrayItemSetOnEvent(-1, "Stop") TrayItemSetState($cStop, $GUI_DISABLE) ; Not running at first Global $f = 0 TraySetState() While 1 Sleep(10) ; Look for start If $f = 1 Then ; Adjust tray menu items TrayItemSetState($cStart, $GUI_DISABLE) TrayItemSetState($cStop, $GUI_ENABLE) ; Run the function _Func() EndIf WEnd Func _Func() $nBegin = TimerInit() ConsoleWrite("Running" & @CRLF) While 1 ; Look for the flag If $f = 0 Then Exit EndIf ; Show function running If TimerDiff($nBegin) > 5000 Then ConsoleWrite("Running" & @CRLF) $nBegin = TimerInit() EndIf WEnd EndFunc ;==>_Func Func Start() $f = 1 EndFunc ;==>Start Func Stop() $f = 0 EndFunc ;==>StopAll clear? Please ask if not. 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...
VVvKamper Posted October 20, 2013 Author Share Posted October 20, 2013 I do not understand why events a not called in my example when i in start() loop, but i understand your solution and it helps me, thank you) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 20, 2013 Moderators Share Posted October 20, 2013 VVvKamper,As explained in the tutorial, AutoIt will not let you break into running functions easily. So when you entered your Start function via an OnEvent call you could never action the Stop to end it. That is why you need to enter the function from the idle loop as I showed. 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