Sign in to follow this  
Followers 0
themoog

While....Wend n00b q

5 posts in this topic

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

Share this post


Link to post
Share on other sites



Take a look at ProcessExists

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

Share this post


Link to post
Share on other sites

#3 ·  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

Share this post


Link to post
Share on other sites

I wondered if I need a delay, but solid advice guys process exists is what ill try :)

Thanks all

Neil

Share this post


Link to post
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. :)

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