Sign in to follow this  
Followers 0
zivt

GUISetOnEvent in For / While

9 posts in this topic

Hi,

during loop of while or For , events of GUISetOnEvent (functions) are not implimented.

the call to the events are made at the end of the loop.

is there any way to check if event happenes during the loop?

Thanks,

Ziv

Share this post


Link to post
Share on other sites



Have you changed Opt("GuiOnEventMode", 1)?

If that doesn't fix it, please post a short demo script showing your issue.

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

; GUI

$DlgHnd= GuiCreate("My App", @DesktopWidth-50,@DesktopHeight-50,0,0)

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

GUISetState(@SW_SHOW)

; Menu

local $FileMenue = GUICtrlCreateMenu("File")

local $DoMyWhile = GUICtrlCreateMenuItem("Do_While", $FileMenue)

GUICtrlSetOnEvent($DoMyWhile , "MyWhile")

While 1

WEnd

Func CLOSEClicked()

Exit

EndFunc

Func MyWhile()

While 1

WEnd

EndFunc

Affter pressing "Do_While" menu option , try to close the dialog (Press the "X").

dialog "CLOSEClicked" evenet will not started.

Thanks,

Ziv

Share this post


Link to post
Share on other sites

What do you think this code is doing?

While 1
WEnd

No sleep in-between = 100% CPU Utilization

While 1/WEnd = infinite loop

What's the purpose of this piece of code? Of manually starting a While loop?

If you want a loop started manually, at least put something to break the loop, otherwise your script will hang everytime.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

I added sleep to the example of 1sec to the while , still the event is not started.

This is just an example...

the real application is read a long file...

Bottom line:

Sleep is not fix this issue.

Share this post


Link to post
Share on other sites

Do you have any idea?

Share this post


Link to post
Share on other sites

During function event , other events are waiting for the function to finish.

is it bug?

is there a workaround for this issue?

Thanks,

Ziv

Share this post


Link to post
Share on other sites

Never put time consuming stuff or blocking functions (i.e. MsgBox()) inside an event handling function. Further event processing is blocked until each event is finished. An event function should be minimalist and fast in returning to the main loop:

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

Global $hDlgHnd, $idFileMenue, $idDoMyWhile, $idLabel, $f_Run = False, $iCount = 0

; GUI
$hDlgHnd = GUICreate("My App", @DesktopWidth - 50, @DesktopHeight - 50, 0, 0)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")

; Menu
$idFileMenue = GUICtrlCreateMenu("File")
$idDoMyWhile = GUICtrlCreateMenuItem("Do_While", $idFileMenue)
GUICtrlSetOnEvent($idDoMyWhile, "MyWhile")

; Label
$idLabel = GUICtrlCreateLabel("Count = " & $iCount, 20, 20, 200, 20)

; Main loop
GUISetState(@SW_SHOW)
While 1
    Sleep(100)
    If $f_Run Then
        $iCount += 1
        ControlSetText($hDlgHnd, "", $idLabel, "Count = " & $iCount)
    EndIf
WEnd

Func CLOSEClicked()
    Exit
EndFunc   ;==>CLOSEClicked

Func MyWhile()
    $f_Run = Not $f_Run
EndFunc   ;==>MyWhile

:mellow:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

OK,

Thats what i thought.

Thanks,

Ziv

Share this post


Link to post
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
Sign in to follow this  
Followers 0