Jump to content

question about the inner workings of AutoIT


Recommended Posts

ok, I've created a script that is designed to run in the background and because I'm a forgetful person it pops up reminders at certain times

here is an example of the scrip, I have cut most of it's content and altered the real expiry date of my credit card :D

CODE
Do

; Credit Card

If @YEAR=2012 And @MON=05 And @MDAY=05 And @HOUR=00 And @MIN=00 And @Sec=00 Then MsgBox(4096, "Reminder", "Your Credit Card Expires in 1 Month on 06-05-2012")

If @YEAR=2012 And @MON=05 And @MDAY=27 And @HOUR=00 And @MIN=00 And @Sec=00 Then MsgBox(4096, "Reminder", "Your Credit Card Expires in 1 Week on 06-05-2012")

If @YEAR=2012 And @MON=05 And @MDAY=29 And @HOUR=00 And @MIN=00 And @Sec=00 Then MsgBox(4096, "Reminder", "Your Credit Card Expires in 1 Day on 06-05-2012")

Until Not ProcessExists("System")

now when run in this form it chews up processor power to 100 percent, but when I introduced a Sleep(1) it dropped to almost nothing, I was under the impression it executes every microsecond by default anyway?

does anyone know what it's doing when their is no sleep, why it's chewing up so much processor, and is my solution the best one? does anyone know a better way to minimise processor use, since I plan to have this script running indefinitly.

oh is my not processexists("system") the best way to keep it going forever as well?

Link to comment
Share on other sites

For the second question, you are using a Do loop in a totally unnecessary way. Use a While loop instead.

While 1
    If @YEAR = 2012 And @MON = 05 And @MDAY = 05 And @HOUR = 00 And @MIN = 00 And @SEC = 00 Then MsgBox(4096, "Reminder", "Your Credit Card Expires in 1 Month on 06-05-2012")
    If @YEAR = 2012 And @MON = 05 And @MDAY = 27 And @HOUR = 00 And @MIN = 00 And @SEC = 00 Then MsgBox(4096, "Reminder", "Your Credit Card Expires in 1 Week on 06-05-2012")
    If @YEAR = 2012 And @MON = 05 And @MDAY = 29 And @HOUR = 00 And @MIN = 00 And @SEC = 00 Then MsgBox(4096, "Reminder", "Your Credit Card Expires in 1 Day on 06-05-2012")
WEnd
Link to comment
Share on other sites

For the second question, you are using a Do loop in a totally unnecessary way. Use a While loop instead.

While 1
    If @YEAR = 2012 And @MON = 05 And @MDAY = 05 And @HOUR = 00 And @MIN = 00 And @SEC = 00 Then MsgBox(4096, "Reminder", "Your Credit Card Expires in 1 Month on 06-05-2012")
    If @YEAR = 2012 And @MON = 05 And @MDAY = 27 And @HOUR = 00 And @MIN = 00 And @SEC = 00 Then MsgBox(4096, "Reminder", "Your Credit Card Expires in 1 Week on 06-05-2012")
    If @YEAR = 2012 And @MON = 05 And @MDAY = 29 And @HOUR = 00 And @MIN = 00 And @SEC = 00 Then MsgBox(4096, "Reminder", "Your Credit Card Expires in 1 Day on 06-05-2012")
WEnd
Did you try that? It will peg the CPU also, and for the same reason. The loop needs a Sleep() in it wheter it's a Do/Until or While/WEnd.

Something that needs to update that rarely should probably be a scheduled task, though. It doesn't need to be running all the time.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Did you try that? It will peg the CPU also, and for the same reason. The loop needs a Sleep() in it wheter it's a Do/Until or While/WEnd.

Something that needs to update that rarely should probably be a scheduled task, though. It doesn't need to be running all the time.

:D

Or a timer(s)

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Or a timer(s)

Even if you use TimerInit()/TimerDiff() for the timing, or use AdLibEnable(), there still has to be a loop to keep the script running, and that will still require a Sleep() to not spike the CPU.

PHhbbbbbbbbbbbbbbst! :D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Even if you use TimerInit()/TimerDiff() for the timing, or use AdLibEnable(), there still has to be a loop to keep the script running, and that will still require a Sleep() to not spike the CPU.

PHhbbbbbbbbbbbbbbst! :D

I said timer(s) not TimerInit/TimerDiff. "_Timer_xxxx"

PHhbbbbbbbbbbbbbbst! :D

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Did you try that? It will peg the CPU also, and for the same reason. The loop needs a Sleep() in it wheter it's a Do/Until or While/WEnd.

Something that needs to update that rarely should probably be a scheduled task, though. It doesn't need to be running all the time.

:D

I was solely answering his second question as Tomb had already answered his first. I just directly transfered his code from a Do loop to a While loop to show him how.

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