Sign in to follow this  
Followers 0
IanN1990

[Solved] General Question about AdlibRegister

5 posts in this topic

#1 ·  Posted (edited)

Hi,

I am writing a function which exits the script at 12pm.

I thought instead of pooling or checking the time every x seconds, I could do this?

#NoTrayIcon
AdlibRegister("ExitScript", (86400-@Sec-((@hour*60)+@min)*60)*1000)

While 1
   sleep(100)
WEnd

Func ExitScript()
   Exit
EndFunc

Is there any dangers of using a 86400000 AdlibRegister? I cant find anything in the help file which states a max value.

Edited by IanN1990

Share this post


Link to post
Share on other sites



Should be fine, I have used large values before without issue.

Though I think best practice has AdlibRegister used for fast repeated passes for a certain event more so than a long term timer, thats not to say it wont work or is a bad idea.

Share this post


Link to post
Share on other sites

The help file states:

The adlib function should be kept simple as it is executed often and during this time the main script is paused. Also, the time parameter should be used carefully to avoid CPU load.

I would personally go with polling the system time, but it is just that - personal preference. The questions you should ask yourself are: Are there any other actions in the script that are failing because of the pausing during the AdlibRegister check? and Is using it in this manner creating a noticeable CPU increase as opposed to other methods? If the answer to both is no, then it sounds like you've answered your own question.


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

Two  things you should know:-
My english speaking culture has the convention of 12pm standing for 12:00 midday; and,
The "Time" parameter in the AdlibRegister function is in milliseconds, not seconds.

So in your script (in post#1), if the script was started at 22:30:25,  the adlib function, "ExitScript", would be called every 5.375secs,
where 5375ms  =  86400 - 25 - ((22 * 60) + 30) * 60 = 86400 - @Sec - ((@hour * 60) +@min) * 60  = (equals) the actual time value parameter when the adlib function is registered.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Well spotted, i had not implemented the code yet so i didn't notice this problem!

I have updated original code so it benefits others :)

Edited by IanN1990

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