Jump to content

Confused by AdlibRegister/AdlibUnRegister


Go to solution Solved by Jos,

Recommended Posts

Posted (edited)

 

Using latest Autoit

The following code never gets to the third line (msgbox).

Why?
 

CheckWorkers()
Sleep(1000)
MsgBox(0,0,0);never gets here


Func CheckWorkers()

    AdlibUnRegister("CheckWorkers")

    Sleep(1000)
    AdlibRegister("CheckWorkers", 1000)

EndFunc

The bottom line is, if the duration of the function is >= Adlib interval, it will run forever. No matter if you did AdlibUnRegister on function start or not.

Edited by milos83
Posted

That is a truly bad written code.  What would be the purpose of creating such a bad logic ?  If you are trolling us to explain why, I suggest you take the time to test you false assumptions.

Posted (edited)

I am guessing if the duration of AdlibRegister("CheckWorkers", 1000) is equal to the first Sleep(1000), it cannot ever reach that Sleep, because you scheduled it to run CheckWorkers.

Edited by lIlIIlIllIIIIlI
Posted
2 hours ago, milos83 said:

The following code never gets to the third line (msgbox). Why ?

Global $iSleep = 500 ; 1000
codeIsAtLineNumber()
CheckWorkers()
codeIsAtLineNumber()
Sleep($iSleep)
codeIsAtLineNumber()
MsgBox(262144, "0", "0", 10) ;never gets here
codeIsAtLineNumber()

Func CheckWorkers()
    codeIsAtLineNumber()
    AdlibUnRegister("CheckWorkers")
    Sleep($iSleep)
    AdlibRegister("CheckWorkers", 1000)
    codeIsAtLineNumber()
EndFunc   ;==>CheckWorkers

Func codeIsAtLineNumber($iScriptLineNumber = @ScriptLineNumber)
    ConsoleWrite("@@(" & $iScriptLineNumber & ") : " & @MIN & ":" & @SEC & "." & @MSEC & @CRLF)
EndFunc   ;==>codeIsAtLineNumber

..because, it interrupts the main code to run the AdLib. And you don't give it a chance to do anything else.

37 minutes ago, Nine said:

That is a truly bad written code.

Ain't that the truth.

2 hours ago, milos83 said:

The bottom line is,...

I don't know what the bottom line is. Looking at parallel processing in the WiKi would be the thing to do if the other function is so ..., time consuming ?

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted
On 2/20/2025 at 4:17 AM, Nine said:

That is a truly bad written code.  What would be the purpose of creating such a bad logic ?  If you are trolling us to explain why, I suggest you take the time to test you false assumptions.

 

On 2/20/2025 at 4:58 AM, argumentum said:

..because, it interrupts the main code to run the AdLib. And you don't give it a chance to do anything else.

Ain't that the truth.

I don't know what the bottom line is. Looking at parallel processing in the WiKi would be the thing to do if the other function is so ..., time consuming ?

Both of you are missing the point.

I am Unregistering AdLib so it doesn't trigger again right after finishing.

My assumption was that by unregistering and then re-registering it at the very exit of the function, it will have a 1s delay between function runs.

This is not the case. It runs right away.

Why is this?

From the helpfile :

Quote

note that the first call to the function is after the specified time period and not immediately the function is registered.

This is not true if done from the actual function.

  • Developers
  • Solution
Posted

It looks like the AdlibUnRegister("CheckWorkers") doesn't get performed until the called interrupt function by AdlibRegister("CheckWorkers", 1000) ends!
Since you do the AdlibRegister("CheckWorkers", 1000) again before the Interrupt call ends, it looks like the counter doesn't get reset at all.

The example you posted is really some "wrong coding logic" where you want to stop an interrupt happening in the interrupt call itself, which would never happen anyway!

I haven't checked the internal code for this, but some tests I did with consolewrite() debug lines seem to prove this.

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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
  • Recently Browsing   0 members

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