Sign in to follow this  
Followers 0
ShawnW

Is there a different sleep method?

7 posts in this topic

I have the need to delete some files while explorer is temporarily closed. I also need to slow certain things down with sleep commands. What I have discovered though is that Sleep means squat when explorer is closed.

Shawn

Share this post


Link to post
Share on other sites



... What I have discovered though is that Sleep means squat when explorer is closed.

Shawn

Care to explain?

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Ok here is the part of the code that I'm talking about. All that is really before this is building the arrays of file and directory paths.

; Kill Processes And services
Run("sc stop Spooler")
ProcessClose("explorer.exe")
Sleep(3000)

; Delete the files and directories from the list
For $i = 0 To UBound($files)-1
    If FileExists($files[$i]) And Not FileDelete($files[$i]) Then Logger("Failed to delete file: " & $files[$i])
Next
For $i = 0 To UBound($dirs)-1
    If FileExists($dirs[$i]) And Not DirRemove($dirs[$i],1) Then Logger("Failed to remove directory: " & $dirs[$i])
Next
Sleep(2000)

; Start Processes
Run("explorer.exe")
Run("sc start Spooler")
Sleep(3000)

Without the sleeps it all goes uber fast and certain things get missed because they are in use. But the sleeps don't pause at all. I tried adding a sleep before explorer closes and it works fine. But then the ones after get shot through as if they were not there.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I tried this on my win7/x64 pc and worked fine running from SciTE with F5...

ProcessClose("explorer.exe")
For $x = 1 to 10
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : Sleep(2000) = ' & Sleep(2000) & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
Next

Explorer was obviously already restarted by the OS before the loop ended.

What OS are you testing on?

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Ok here is the part of the code that I'm talking about. All that is really before this is building the arrays of file and directory paths.

; Kill Processes And services
Run("sc stop Spooler")
ProcessClose("explorer.exe")
Sleep(3000)

; Delete the files and directories from the list
For $i = 0 To UBound($files)-1
    If FileExists($files[$i]) And Not FileDelete($files[$i]) Then Logger("Failed to delete file: " & $files[$i])
Next
For $i = 0 To UBound($dirs)-1
    If FileExists($dirs[$i]) And Not DirRemove($dirs[$i],1) Then Logger("Failed to remove directory: " & $dirs[$i])
Next
Sleep(2000)

; Start Processes
Run("explorer.exe")
Run("sc start Spooler")
Sleep(3000)

Without the sleeps it all goes uber fast and certain things get missed because they are in use. But the sleeps don't pause at all. I tried adding a sleep before explorer closes and it works fine. But then the ones after get shot through as if they were not there.

Try this:

; Kill Processes And services
Run("sc stop Spooler")
ProcessClose("explorer.exe")
While ProcessExists("explorer.exe")
    Sleep(100)
WEnd

; Delete the files and directories from the list
For $i = 0 To UBound($files)-1
    If FileExists($files[$i]) And Not FileDelete($files[$i]) Then Logger("Failed to delete file: " & $files[$i])
Next
For $i = 0 To UBound($dirs)-1
    If FileExists($dirs[$i]) And Not DirRemove($dirs[$i],1) Then Logger("Failed to remove directory: " & $dirs[$i])
Next

; Start Processes
Run("explorer.exe")
Run("sc start Spooler")
While Not ProcessExists("explorer.exe")
    Sleep(100)
WEnd

Nevermind, I see what you're talking about now. The post above mine should work well for this. ;)

Sorry if I caused any confusion.

Edited by cembry90

AutoIt Stuff:

 

UDFs: {Grow}

Share this post


Link to post
Share on other sites

XP Pro SP3.

Wish it were 7 but my boss is like the least progressive, farthest behind, most scared to death of change IT guy that there ever could be.

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