themoog Posted July 1, 2008 Share Posted July 1, 2008 Why does this code run twice? CODEWhile WinWaitClose("[CLASS:Notepad]", "") Run("notepad.exe") WEnd I just want to keep notepad open no matter what. Many Thanks Neil Link to comment Share on other sites More sharing options...
mwpeck Posted July 1, 2008 Share Posted July 1, 2008 Take a look at ProcessExists Basically, do an infinite loop and if the process does not exist then run("notepad.exe") Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 1, 2008 Share Posted July 1, 2008 (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 July 1, 2008 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 More sharing options...
themoog Posted July 1, 2008 Author Share Posted July 1, 2008 I wondered if I need a delay, but solid advice guys process exists is what ill try Thanks all Neil Link to comment Share on other sites More sharing options...
mwpeck Posted July 1, 2008 Share Posted July 1, 2008 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now