Jump to content

How does Adlib Work?


Recommended Posts

I'm going to go into a hypothetical question here. I can't post my code, because it doesn't exist. This is basically a "What happens when...?" question.

I'm not looking to get into a discussion of here's a better way to do it blah blah blah... I just want to know "how" the adlib function handles a certain situation... So, here goes the "hypothetical situation":

Say we have a script with many execution paths, depending on what all is installed on the machine and what needs to be updated. Certain Sections of the script may encounter some random message boxes, like security warnings, and print confirmations etc. but these messageboxes will not ALWAYS appear. If they do appear, it won't always be at the same time, like the print confirmation will take longer or shorter depending on how much the printer is backed up. So AdLibbing Seems like the logical choice.

Say there are about 20 different popup messages that "might" happen, but I know that some will only happen at certain times, like "Communication error happened in Program X" is only going to happen while program x is runnning. But it's only the active window for about 1/2 the time the script is running, but not in one consecutive section. More like three five minute sections here and there.

In some cases, the first out of three sections won't need to execute (like i said multiple execution paths) so now we're running 2 sections of 5 minutes each.

So program x is in the background basically pinging a server for the whole script, but we're only driving program x for 10 or 15 minutes. If this ping action fails, it pops up a modal msgbox that we need to get rid of before we can do anything else on the computer.

So in all three functions I AdLibEnable ( "ClearPingError" ) Because the program x doesn't start until the first time we need to use it, and we don't want to sacrifice "any" performance with the Adlib function prior to Program X being launched.

Also remember we've got say 20 different adlibs to handle different messageboxes for different applications. so we don't want to just adlib one function that handles all the possible messageboxes, because that's a cut on performance. We only want to adlib the ones we need, which is determined at runtime (when the program starts we start handling that application's popups.)

QUESTION HERE:

In this type of situation, does AdLibEnable cause there to be three instances of ClearPingError to be running in adlib mode, or is autoit smart enough to realize that ClearPingError is already running, so we don't have to start another copy?

Please remember, I can't post any code. This is JUST a What Happens When.... question because I'm curious.

Thanks,

Todd

Link to comment
Share on other sites

Instead of having 20 adlib functions, what about having a single adlib function, enabled at the beginning of your script that looks like the following:

AdlibEnable("GeneralAdlibFunction")

Func GeneralAdlibFunction()
    If WinExists("x") Then
        If WinExists("Communication error happened in Program X") Then Send("{ENTER}")
    EndIf
    If WinExists("print completed") Then Send("{ENTER}")
EndFunc

And so on...

So long as you have a series of If's making sure X is running before doing everything related to X, you shouldn't sacrifice "much" performance - if none of the adlib functions are needed, it's only checking 20 if's and ending before the next call. If it degrades, then you could bump up the interval to 500ms or more...

Edit: However, in response to your actual question, even if AutoIt's not smart enough not to call multiple instances of a function, you can make it so. Create a global variable called $PingAdlibRunning that's set to 0 initally. Then have the first line of your ping adlib check the value of $PingAdlibRunning and Return() if it's 1. Then the second line of your Ping adlib function will set $PingAdlibRunning to 1. Finally, the last line of the Ping Adlib function would set $PingAdlibRunning back to 0 just before returning so it's all set to run again.

Edited by james3mg
"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
Share on other sites

I'm going to go into a hypothetical question here. I can't post my code, because it doesn't exist. This is basically a "What happens when...?" question.

I'm not looking to get into a discussion of here's a better way to do it blah blah blah... I just want to know "how" the adlib function handles a certain situation... So, here goes the "hypothetical situation":

Say we have a script with many execution paths, depending on what all is installed on the machine and what needs to be updated. Certain Sections of the script may encounter some random message boxes, like security warnings, and print confirmations etc. but these messageboxes will not ALWAYS appear. If they do appear, it won't always be at the same time, like the print confirmation will take longer or shorter depending on how much the printer is backed up. So AdLibbing Seems like the logical choice.

Say there are about 20 different popup messages that "might" happen, but I know that some will only happen at certain times, like "Communication error happened in Program X" is only going to happen while program x is runnning. But it's only the active window for about 1/2 the time the script is running, but not in one consecutive section. More like three five minute sections here and there.

In some cases, the first out of three sections won't need to execute (like i said multiple execution paths) so now we're running 2 sections of 5 minutes each.

So program x is in the background basically pinging a server for the whole script, but we're only driving program x for 10 or 15 minutes. If this ping action fails, it pops up a modal msgbox that we need to get rid of before we can do anything else on the computer.

So in all three functions I AdLibEnable ( "ClearPingError" ) Because the program x doesn't start until the first time we need to use it, and we don't want to sacrifice "any" performance with the Adlib function prior to Program X being launched.

Also remember we've got say 20 different adlibs to handle different messageboxes for different applications. so we don't want to just adlib one function that handles all the possible messageboxes, because that's a cut on performance. We only want to adlib the ones we need, which is determined at runtime (when the program starts we start handling that application's popups.)

QUESTION HERE:

In this type of situation, does AdLibEnable cause there to be three instances of ClearPingError to be running in adlib mode, or is autoit smart enough to realize that ClearPingError is already running, so we don't have to start another copy?

Please remember, I can't post any code. This is JUST a What Happens When.... question because I'm curious.

Thanks,

Todd

actually the performance of the adlibfunction in question would be completely determined by the person that coded it. personally, the way i'd do it would be to have 1 adlib function that is enabled whenever any of the popups could occur. it can have an if structure for every popup you're trying to avoid, like (If WinExists("Popup1","Popup1 text" Then...) even with 20 different if statements, when there are 20 checks that don't do anything, meaning none of the popups are present, the adlib function will still finish very quickly. if you put an interval of like 200 ms on it, then you will probably not even notice an additional drain on the resources, and it will begin handling any of your popups within about a quarter of a second of their appearance...
Link to comment
Share on other sites

actually the performance of the adlibfunction in question would be completely determined by the person that coded it. personally, the way i'd do it would be to have 1 adlib function that is enabled whenever any of the popups could occur. it can have an if structure for every popup you're trying to avoid, like (If WinExists("Popup1","Popup1 text" Then...) even with 20 different if statements, when there are 20 checks that don't do anything, meaning none of the popups are present, the adlib function will still finish very quickly. if you put an interval of like 200 ms on it, then you will probably not even notice an additional drain on the resources, and it will begin handling any of your popups within about a quarter of a second of their appearance...

I don't want to know about the performance of the adlib functions that have been created. I'd like to know how AdLibEnable () works.

If I Have in my code

AdLibEnable ( "myAdlib1" )
AdLibEnable ( "myAdlib1" )
AdLibEnable ( "myAdlib1" )

Func myAdlib1 ()
 ;Do some stuff
EndFunc

Is myAdlib1 going to be running 3 times, simultaneously. Or will it just run once, even though I've called it 3 times.

Link to comment
Share on other sites

  • Developers

Is myAdlib1 going to be running 3 times, simultaneously. Or will it just run once, even though I've called it 3 times.

Nope only One adlib is supported and that will be the last one defined.

try:

AdLibEnable ( "myAdlib1" )
Sleep(1000)
AdLibEnable ( "myAdlib2" )
Sleep(1000)
AdLibEnable ( "myAdlib3" )
Sleep(1000)

Func myAdlib1 ()
    ConsoleWrite("1")
EndFunc
Func myAdlib2 ()
    ConsoleWrite("2")
EndFunc
Func myAdlib3 ()
    ConsoleWrite("3")
EndFunc
Edited by JdeB

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.
  :)

Link to comment
Share on other sites

Is myAdlib1 going to be running 3 times, simultaneously. Or will it just run once, even though I've called it 3 times.

See my edit in post 2 above for a way to can make sure it's only run once. I don't know personally if AutoIt would do this on its own, or even if you can HAVE more than one adlib enabled at a time. But if you build in your own check, then you don't need to worry about it running three times.

Edit: JdeB's quicker - and much more knowledgable - than I :D Didn't know he'd posted until I'd already posted too. Thanks JdeB

Edited by james3mg
"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
Share on other sites

Instead of having 20 adlib functions, what about having a single adlib function, enabled at the beginning of your script that looks like the following:

AdlibEnable("GeneralAdlibFunction")

Func GeneralAdlibFunction()
    If WinExists("x") Then
        If WinExists("Communication error happened in Program X") Then Send("{ENTER}")
    EndIf
    If WinExists("print completed") Then Send("{ENTER}")
EndFunc

And so on...

So long as you have a series of If's making sure X is running before doing everything related to X, you shouldn't sacrifice "much" performance - if none of the adlib functions are needed, it's only checking 20 if's and ending before the next call. If it degrades, then you could bump up the interval to 500ms or more...

Edit: However, in response to your actual question, even if AutoIt's not smart enough not to call multiple instances of a function, you can make it so. Create a global variable called $PingAdlibRunning that's set to 0 initally. Then have the first line of your ping adlib check the value of $PingAdlibRunning and Return() if it's 1. Then the second line of your Ping adlib function will set $PingAdlibRunning to 1. Finally, the last line of the Ping Adlib function would set $PingAdlibRunning back to 0 just before returning so it's all set to run again.

You know, I read your initial response before you made the edit, and wasn't real happy with your response, but your added suggestion in the edit kind of helps me. But unfortunately it's not the exact answer I'm lookin for, simply because even though it's quite minimal, there is a performance loss. and it's ugly with it's global variables, and starting a function (by default) every 250ms just to return after one operation (the comparison of $PingAdlibRunning). Hey, i'm picky, but in my defense, that is an extra operation 4 times a second, and say the script is so big it takes an hour to run, that's on the order of about 15000 useless operations.

That's like a bad case of OCD.

Link to comment
Share on other sites

Nope only One adlib is supported and that will be the last one defined.

try:

AdLibEnable ( "myAdlib1" )
Sleep(1000)
AdLibEnable ( "myAdlib2" )
Sleep(1000)
AdLibEnable ( "myAdlib3" )
Sleep(1000)

Func myAdlib1 ()
    ConsoleWrite("1")
EndFunc
Func myAdlib2 ()
    ConsoleWrite("2")
EndFunc
Func myAdlib3 ()
    ConsoleWrite("3")
EndFunc
thanks JdeB. That's exactly what I was lookin for... don't know why i didnt just try something like that on my own... so really, to handle all the random popups they'd all have to be accounted for in one adlib function, but we'd probably want to reset the delay to something a little higher so that it's not boggin down the machine lookin for stuff...
Link to comment
Share on other sites

You can enable or disable Adlib anywhere within your script for good management. Also you can change which function to use for the Adlib operation. It is all up to the good use of it to save resources where suitable or to set an Adlib to check for issues. The time parameter can also be used to make Adlib execute economically while the script executes.

Hypothetically, Adlib can be quite wide with it's uses as to how it is implemented through the script.

A simple example below of how AdlibDisable can be used to save CPU when Adlib is not needed and selecting different functions through the course of the script as needed.

; Adlib 1
AdlibEnable('_1')
Sleep(3000)

; Save CPU here
AdlibDisable()
Sleep(3000)

; Adlib 2
AdlibEnable('_2')
Sleep(5000)

; Save CPU here
AdlibDisable()
Sleep(3000)

; Adlib 3
AdlibEnable('_3')
Sleep(5000)

Func _1()
    MsgBox(0, 'Task', 1, 1)
EndFunc

Func _2()
    MsgBox(0, 'Task', 2, 1)
EndFunc

Func _3()
    MsgBox(0, 'Task', 3, 1)
EndFunc

:D

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...