Jump to content
Sign in to follow this  
MonsieurOUXX

events handling: when is it done?

Recommended Posts

MonsieurOUXX

Here is a little example (the syntax might not be perfect, it's not a real script)

Func EventHandling()
   $var = 1 ;do something
EndFunc

Func CreateWindow()
    $gui = GUICreate(...)
    GUISetOnEvent($GUI_EVENT_CLOSE, "EventHandling")
EndFunc

Opt("GUIOnEventMode", 1)
CreateWindow()

while 1
    sleep(100)
wend

Now here is my question : When is the script of "EventHandling" called?Let me explain : Autoit is monothreaded... So it means that when the code of "EventHandling" is executed, then autoit is interrupting the execution of, let's say, the main loop (while 1...)

How does it decide when it is going to interrupt something else? Am I misunderstanding the way it works?

Share this post


Link to post
Share on other sites
martin

Here is a little example (the syntax might not be perfect, it's not a real script)

Func EventHandling()
   $var = 1 ;do something
EndFunc

Func CreateWindow()
    $gui = GUICreate(...)
    GUISetOnEvent($GUI_EVENT_CLOSE, "EventHandling")
EndFunc

Opt("GUIOnEventMode", 1)
CreateWindow()

while 1
    sleep(100)
wend

Now here is my question : When is the script of "EventHandling" called?Let me explain : Autoit is monothreaded... So it means that when the code of "EventHandling" is executed, then autoit is interrupting the execution of, let's say, the main loop (while 1...)

How does it decide when it is going to interrupt something else? Am I misunderstanding the way it works?

I think it's as simple as this (Though I am just guessing)

All events are queued.

The AutoIt script responds to each one in turn. If it's in a handler for one event it won't respond to the next one in the queue until it returns from the handler. That is why, if you want one event to trigger an action and have another event have an immediate effect even though the script is still dealing with the first one you have to make the first one just set a flag and return. Then in the main loop call a function if that flag is set and reset the flag. Then while that function is executing it can respond to the next event.

Presumably it is not because AutoIt cannot multithread that it behaves this way, but maybe because it could easily get in a mess otherwise. After all, if you use a HotKey, then you can call a function and while that function is executing you can call it again and so on, and each call halts the progress of the previous one then continues the previous one, so I assume that AutoIt could have done that with events. But as I said, I am just guessing.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
MonsieurOUXX

All events are queued.

The AutoIt script responds to each one in turn. If it's in a handler for one event it won't respond to the next one in the queue until it returns from the handler.

....

Each call halts the progress of the previous one then continues the previous one, so I assume that AutoIt could have done that with events. But as I said, I am just guessing.

I know all events are queued. But that's not what I'm asking.

My question is : when are they unqueued?

Above, you seem to say that they are kinda unqueued immediately, because the firing of an event immediately interrupts the rest of the script to execute the code that has been previously associated to that event using GUISetOnEvent.

Can someone confirm that?

Share this post


Link to post
Share on other sites
MonsieurOUXX

Can someone confirm that?

Nobody answering... I will close this thread (general question) and create a new thread (with my specific script and an highlight of what's going wrong with it).

Edited by MonsieurOUXX

Share this post


Link to post
Share on other sites
martin

I know all events are queued. But that's not what I'm asking.

My question is : when are they unqueued?

It's not what I said. I told you when I think they are unqueued.

Above, you seem to say that they are kinda unqueued immediately, because the firing of an event immediately interrupts the rest of the script to execute the code that has been previously associated to that event using GUISetOnEvent.

I did not say that! I said nothing at all like that. Please read what I said again.

Can someone confirm that?

Confirm that what you say I said is correct? Then no it isn't.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.