PKG, The "flag and wrapper" method is certainly the easiest way in this case - this works for me:
#include<GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
$FL = False
Local $MainForm = GUICreate("Win_App-1", 550, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "WinExit")
Global $MyEditBox = GUICtrlCreateEdit("", 5, 30, 540, 270)
GUICtrlSetBkColor($MyEditBox, 0xFF6347)
Global $RunButton = GUICtrlCreateButton("&Run", 120, 420, 70, 30)
GUICtrlSetOnEvent($RunButton, "Run_DataLoop")
Global $StopButton = GUICtrlCreateButton("&Stop", 200, 420, 70, 30)
GUICtrlSetOnEvent($StopButton, "Run_DataLoop")
GUISetState()
While 1
Sleep(10)
; Look for the flag
If $FL Then
; Run the function
DataLoop()
EndIf
WEnd
Func WinExit()
Exit 0
EndFunc ;==>WinExit
; This function will always run as the function to interrupt was started from the idle loop
Func Run_DataLoop()
Switch @GUI_CtrlId
Case $RunButton
$FL = True
Case $StopButton
$FL = False
EndSwitch
EndFunc
Func DataLoop()
; Look for the flag
While $FL
ToolTip("Func Running")
Sleep(10)
WEnd
; And break out if it is cleared
ToolTip("Function Stopped")
Sleep(500)
ToolTip("")
Return
EndFunc ;==>DataLoop
Does it work for you too? M23