Jump to content

make a while loop end after 10min?


epicfail
 Share

Recommended Posts

I'll explain it. It's not really specific to the looping.

TimerDiff returns the time difference (in milliseconds) from a previous call to TimerInit().

For example we have this script:

$init = TimerInit()

While TimerDiff($init) <= 1000
    Sleep(100)
Wend

This script will make 10 loops. Why?

First loop 0ms, second loop 100ms, third loop 300ms, fourth loop 400ms. Then loop 10 = 1000ms, loop 11 = 1100ms but that's too much. 1100 <= 1000 is False.

So what you need to do now is correct your script, so that the value that the time difference must be smalelr than 10 minutes expressed in milliseconds.

@Volly, epicfail is a little slow to understand. He has the ability to understand many things, but just doesn't see the connection between some things. He needs some special help. 8)

Edited by Manadar
Link to comment
Share on other sites

i was doing some playing around and came up with this not sure what 1 is right both seem to work. What 1 is the right way?

$init = TimerInit()

While TimerDiff($init) <  600000
    If WinActive("Untitled -") Then
        ExitLoop
    EndIf
Wend

$init = TimerInit()

While TimerDiff($init) <  600000
    If WinActive("Untitled -") Then
        ExitLoop
    EndIf
    If TimerDiff($init) > 600000 Then
        ExitLoop
    EndIf
Wend
Link to comment
Share on other sites

$init = TimerInit()

While TimerDiff($init) <  600000
    If WinActive("Untitled -") Then
        ExitLoop
    EndIf
Wend
Exit

Or

$init = TimerInit()

While 1
    If TimerDiff($init) >  600000 Then
        Exit ; Note this says > 600000 instead of < 600000
    EndIf
    If WinActive("Untitled -") Then
        ExitLoop
    EndIf
Wend
Exit
Edited by Manadar
Link to comment
Share on other sites

I added a sleep in there so the CPU doesn't go crazy.

$init = TimerInit()

While TimerDiff($init) <  600000
    If WinActive("Untitled -") Then
        ExitLoop
    EndIf
    Sleep(50)
Wend
Exit

Or

$init = TimerInit()

While 1
    If TimerDiff($init) >  600000 Then
        Exit ; Note this says > 600000 instead of < 600000
    EndIf
    If WinActive("Untitled -") Then
        ExitLoop
    EndIf
    sleep(50)
Wend
Exit
Link to comment
Share on other sites

ok something else say i have other stuff after my while that i dont want to be done after i exit my loop how would i stop it from doing them? if i use exit it will exit but i want to be able to use my gui still so dont want to fully exit the program.

Link to comment
Share on other sites

; GUI stuff

$result = _WaitForWindow()
If $result = 1 Then
   ; The window was found
Else
   ; There was a time out
EndIf

Func _WaitForWindow()
    Local $init = TimerInit()
    
    While TimerDiff($init) <  600000
        If WinActive("Untitled -") Then
            Return 1
        EndIf
    Wend
    Return 0
EndFunc

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