Jump to content

Recommended Posts

Posted

Why does this code run twice?

CODE
While WinWaitClose("[CLASS:Notepad]", "")

Run("notepad.exe")

WEnd

I just want to keep notepad open no matter what.

Many Thanks

Neil

Posted

Take a look at ProcessExists

Basically, do an infinite loop and if the process does not exist then run("notepad.exe")

Posted (edited)

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
Posted

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

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
×
×
  • Create New...