Jump to content

List of instructions able to "interfere" with the simple script flow


Recommended Posts

Are there other instructions able to "interfere" with the simple script flow like the following?

AdlibRegister ( "function" [, time] )

Opt("GUIOnEventMode", 1)  -   GUICtrlSetOnEvent ( controlID, "function" )

Opt("GUIOnEventMode", 1)  -   GUISetOnEvent ( specialID, "function" [, winhandle] )

 

What happens if one of these events occurs while in a function or while in a loop?  will they wait until the function or loop are finished before interfering?

Link to comment
Share on other sites

AdlibRegister finishes to process the current statement, then the func defined by AdlibRegister is called.

Try this and wait a few seconds while the MsgBox is being displayed. You get no output in the SciTE console pane.

AdlibRegister("_Test", 250)

For $i = 1 To 2
    Sleep(1000)
    MsgBox(0, "", "...")
Next

Func _Test()
    ConsoleWrite("_Test called!" & @LF)
EndFunc   ;==>_Test

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

GUISetOnEvent will complete the function it triggered before it will run another GUISetOnEvent.

A function triggered by GUISetOnEvent can be interrupted by an  Adlib function if the adlib function is polling fast enough to catch the condition.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.8.1
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------


;~ AdlibRegister ( "function" [, time] )


;~ Opt("GUIOnEventMode", 1)  -   GUICtrlSetOnEvent ( controlID, "function" )

;~ Opt("GUIOnEventMode", 1)  -   GUISetOnEvent ( specialID, "function" [, winhandle] )


#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
AdlibRegister("Adlib_Function",50)
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 193, 95, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$lblDisplay = GUICtrlCreateLabel("Field with lots of stuff in it", 24, 16, 121, 17)
$btnGo = GUICtrlCreateButton("GO", 16, 48, 65, 25)
GUICtrlSetOnEvent($btnGo, "btnGoClick")
$btnStop = GUICtrlCreateButton("STOP", 88, 48, 65, 25)
GUICtrlSetOnEvent($btnStop, "btnStopClick")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $y=0
While 1
    Sleep(100)
WEnd

Func Adlib_Function()
    if $y = 25 Then
        msgbox(1,"SUCCESS","$x hit 25")
    EndIf
EndFunc

Func btnGoClick()
    for $x = 0 to 50
        sleep(250)
        $y = $x
        GUICtrlSetData($lblDisplay,"Loop : " & $x &   "$y = " & $y)
    Next
    msgbox(1,"STILL RAN","It still ran")
EndFunc
Func btnStopClick()
    Exit
EndFunc
Func Form1Close()
    Exit
EndFunc
Link to comment
Share on other sites

so:

AdlibRegister action is queued just after the current line/statement

GUICtrlSetOnEvent/GUISetOnEvent action is queued just after the current line/statement unless it's inside a function. If it's inside a function it's queued just after the function

Correct?

Link to comment
Share on other sites

Run my example and let the MsgBox wait for 10 minutes. You won't get more lines in the console pane. So: No, nothing is queued.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Run my example and let the MsgBox wait for 10 minutes. You won't get more lines in the console pane. So: No, nothing is queued.

 

I know it and this is why I wrote that it queue the command after the line/statement (msgbox in your example), indeed ANY statement after msgbox is executed after you close the msgbox.  Where am I wrong?

Link to comment
Share on other sites

from what i've seen in operation there doesn't appear to be any queuing.

It just looks to work a bit like UDP.  Commands fire off and if the system is ready to receive them it does, otherwise they just fall away.

Someone smarter will turn up soon and you'll get a definitive answer.

 

If I trigger an event while a msgbox is open, it's executed after I close the msgbox (and current function ends, if msgbox is inside a function).

Imho events and adLib actions never "fall away".

Edited by Imbuter2000
Link to comment
Share on other sites

I wanted to stress what gruntydatsun said:

from what i've seen in operation there doesn't appear to be any queuing.
It just looks to work a bit like UDP.  Commands fire off and if the system is ready to receive them it does, otherwise they just fall away.

An event occuring during normal execution is executed after the current statement. Any events occurring during a blocking operation (like a MsgBox) are dropped. No queueing of this events happens.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Run this little script. When the MsgBox appears the script waits for 5 seconds. If events were queued you should see 20 lines.. But you see only 1. So all other events were dropped.

AdlibRegister("_Test", 250)

MsgBox(0, "", "Waiting for 5 seconds", 5)
Exit

Func _Test()
    ConsoleWrite("_Test called!" & @LF)
EndFunc   ;==>_Test

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I kindly disagree with both of you...

Try this:

$a = 0
AdlibRegister("_Test", 250)


MsgBox(0, "", "Waiting for 5 seconds", 5)
MsgBox(0, "", "Waiting for 5 seconds", 5)
MsgBox(0, "", "Waiting for 5 seconds", 5)
Exit


Func _Test()
$a += 1
    ConsoleWrite("_Test called! " & $a & @LF)
EndFunc   ;==>_Test

Output:  (without manually closing the msgboxes)
_Test called! 1

_Test called! 2

_Test called! 3

No AdLib action is lost.

The fact is that the Help description of the AdlibRegister is not correct:
"Every 250 ms (or time ms) the specified "function" is called" should be "250 ms (or time ms) *after the AdlibRegister command execution and then after the end of the last specified "function" execution*, the specified "function" is called (queued after the current statement).

About the other type, I'm also daily using a (complex) AutoIT script where if I trigger a GUICtrlSetOnEvent event while a msgbox is on display, the event IS executed... after I close the msgbox.

So my best bet remains the same:

- AdlibRegister action is queued just after the current statement (line...);
- GUICtrlSetOnEvent/GUISetOnEvent action is queued just after the current statement (line...) unless it's inside a function. If it's inside a function it's queued just after the function.

Happy to see evidence that I'm wrong...   I'm here to learn     :)

Edited by Imbuter2000
Link to comment
Share on other sites

It's only queueing one instance of adlibregister, otherwise it should have printed out 20 times and not once per message box.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Better evidence test:
 
$a = 0
AdlibRegister("_Test", 1000)


MsgBox(0, "", "Waiting for 5 seconds", 5)
consolewrite("fast command!" & @CRLF)
MsgBox(0, "", "Waiting for 5 seconds", 5)
consolewrite("fast command!" & @CRLF)
MsgBox(0, "", "Waiting for 5 seconds", 5)
consolewrite("fast command!" & @CRLF)


Exit


Func _Test()
$a += 1
    ConsoleWrite("Adlib executed! " & $a & @LF)
EndFunc   ;==>_Test

Console output:

Adlib executed! 1
fast command!
Adlib executed! 2
fast command!
Adlib executed! 3
fast command!
Edited by Imbuter2000
Link to comment
Share on other sites

It's only queueing one instance of adlibregister, otherwise it should have printed out 20 times and not once per message box.

 

I agree.

So the sentence in the help page rule could be:  "250 ms (or time ms) *after the AdlibRegister command execution and then after the end of the last specified "function" execution*, the specified "function" is called, queued only one time after the current statement".

 

...until you try this:

$a = 0AdlibRegister("_Test", 100)


$t = TimerInit()
consolewrite(TimerDiff($t) & @CRLF)
sleep(1000)
consolewrite(TimerDiff($t) & @CRLF)
sleep(1000)
consolewrite(TimerDiff($t) & @CRLF)
sleep(1000)
consolewrite(TimerDiff($t) & @CRLF)
sleep(1000)
consolewrite(TimerDiff($t) & @CRLF)


Exit


Func _Test()
$a += 1
sleep(300) ; more time than the Adlib frequency time!
    ConsoleWrite("Adlib executed! " & $a & @LF)
sleep(300) ; more time than the Adlib frequency time!
EndFunc   ;==>_Test

and see this output:

0.0064156397900546
Adlib executed! 1
Adlib executed! 2
Adlib executed! 3
Adlib executed! 4
Adlib executed! 5
Adlib executed! 6
Adlib executed! 7
Adlib executed! 8
Adlib executed! 9
Adlib executed! 10
Adlib executed! 11
Adlib executed! 12

Ctrl+interr pressed here to stop it!

?!

Edited by Imbuter2000
Link to comment
Share on other sites

Another interesting case:

$a = 0
AdlibRegister("_Test", 2000)

$t = TimerInit()
consolewrite(TimerDiff($t) & @CRLF)
sleep(10000)
consolewrite(TimerDiff($t) & @CRLF)
sleep(10000)
consolewrite(TimerDiff($t) & @CRLF)
sleep(10000)
consolewrite(TimerDiff($t) & @CRLF)
sleep(10000)
consolewrite(TimerDiff($t) & @CRLF)

Exit


Func _Test()
$a += 1
sleep(300) ; more time than the Adlib frequency time!
    ConsoleWrite("Adlib executed! " & $a & @LF)
sleep(300) ; more time than the Adlib frequency time!
EndFunc   ;==>_Test

Output:

0.00256625591602184
Adlib executed! 1
Adlib executed! 2
Adlib executed! 3
Adlib executed! 4
Adlib executed! 5
10605.4464932434
Adlib executed! 6
Adlib executed! 7
Adlib executed! 8
Adlib executed! 9
Adlib executed! 10
20618.4099350032
Adlib executed! 11
Adlib executed! 12
Adlib executed! 13
Adlib executed! 14
Adlib executed! 15
30644.2579061533
Ctrl+interr pressed to stop it


After all these tests I can deduce these rules:
- the Adlib frequency timer restarts from 0 when the Adlib function/action starts, not when it finishes 
if an Adlib action occurs while a "sleep", it runs immediately, and the sleep timer continues to run while the Adlib function runs
- if an Adlib action occurs while the Adlib function is running, it's queued just after it finishes
Edited by Imbuter2000
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...