Jump to content

While....Wend n00b q


Recommended Posts

Why does this code run twice?

While WinWaitClose("[CLASS:Notepad]", "")
    Run("notepad.exe")
WEnd

I just want to keep notepad open no matter what.

Many Thanks

Neil

Your loop checks too fast. Once you Run() notepad, there is a delay before the new process can create its window. In the meantime, WinWaitClose() returns True and it runs again...

As mwpeck said, watch for the process instead.

You might also want a short sleep() in there to prevent slamming the CPU.

:)

Edited by PsaltyDS
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

Delays are always good for infinite loops (though I missed it in my reply), as an example, a completely empty infinite loop (while 1) uses ~50% of my processor, with a small Sleep(100) in that same loop, it doesnt even register 1% processor usage. So yes, delays even as short as 100 ms are very helpful for loops like yours. :)

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