quietus24 Posted September 22, 2004 Share Posted September 22, 2004 trying to run a progress metere through a loop until a process ends. Got that part working fine. Issue is now that I need to time that out.... Tried the following....but it doesn't exit if Process ends Excluded Variable sets. Any ideas? Thanks.. do If $dif > 2100000 then MsgBox (48, "ATTENTION",$dif) MsgBox (48, "ATTENTION", "Process has timed out.") ProcessClose("notepad.exe") exitloop endif ; Progress Meter ProgressOn("PSTs Processing-Please be patient.", "DO NOT INTERRUPT THIS PROCESS.", "0") For $i = 10 to 100 step 10 sleep(1000) ProgressSet( $i, $i & "") Next ProgressSet(100 , "", "") sleep(500) ProgressOff() Until $procpstrunning = 0 Link to comment Share on other sites More sharing options...
Matt @ MPCS Posted September 22, 2004 Share Posted September 22, 2004 Tried the following....but it doesn't exit if Process endsI do not see any code here that would help in exiting: do If $dif > 2100000 then MsgBox (48, "ATTENTION",$dif) MsgBox (48, "ATTENTION", "Process has timed out.") ProcessClose("notepad.exe") ExitLoop EndIf ; Progress Meter ProgressOn("PSTs Processing-Please be patient.", "DO NOT INTERRUPT THIS PROCESS.", "0") For $i = 10 to 100 step 10 sleep(1000) ProgressSet( $i, $i & "") Next ProgressSet(100 , "", "") sleep(500) ProgressOff() Until $procpstrunning = 0 You could try the following though: dim $MaxTime, $StartSec ; Set the time out length here (in seconds) $MaxTime = 0 $StartSec = @Sec do If @Sec = ($StartSec + $MaxTime) Then ; Loop timed out ExitLoop EndIf If $dif > 2100000 then MsgBox (48, "ATTENTION",$dif) MsgBox (48, "ATTENTION", "Process has timed out.") ProcessClose("notepad.exe") ExitLoop EndIf ; Progress Meter ProgressOn("PSTs Processing-Please be patient.", "DO NOT INTERRUPT THIS PROCESS.", "0") For $i = 10 to 100 step 10 sleep(1000) ProgressSet( $i, $i & "") Next ProgressSet(100 , "", "") sleep(500) ProgressOff() Until $procpstrunning = 0 Just remember to change the line $MaxTime=0 to $MaxTime=whatever timeout you want in seconds. I haven't tested it but the theory sounds clean to me. I hope this helps! *** Matt @ MPCS Link to comment Share on other sites More sharing options...
quietus24 Posted September 22, 2004 Author Share Posted September 22, 2004 (edited) Hey Matt, The DO and UNTIL... The DO "progress meter" UNTIL the ProcessExits value= not exist works very well, and wil exit fine. I excluded this Var set $ProcPStRunning = Processexists ("notepad.exe") But when I put the IF statement(as is example orignially posted) in, to timeout and exit loop it doesnt when Process ends early, but of course does when Timeout is reach. Will check your example. Thanks Much.. Edited September 22, 2004 by quietus24 Link to comment Share on other sites More sharing options...
Matt @ MPCS Posted September 22, 2004 Share Posted September 22, 2004 (edited) I see now where you were attempting to do this, sorry I looked at it and just saw a couple msgboxes without looking at their content. I don't know what $dif contains though because it is not defined or initialized in the script you posted. Looking at it now we may be doing the same things, but here is a new version with more understanding of the task: dim $MaxTime, $StartSec ; Set the time out length here (in seconds) $MaxTime = 0 $StartSec = @Sec do If @Sec = ($StartSec + $MaxTime) Then ; Loop timed out MsgBox (48, "ATTENTION",$dif) MsgBox (48, "ATTENTION", "Process has timed out.") ProcessClose("notepad.exe") ExitLoop EndIf ; Progress Meter ProgressOn("PSTs Processing-Please be patient.", "DO NOT INTERRUPT THIS PROCESS.", "0") For $i = 10 to 100 step 10 sleep(1000) ProgressSet( $i, $i & "") Next ProgressSet(100 , "", "") sleep(500) ProgressOff() Until Not ProcessExists("notepad.exe") Hope that makes more sense. *** Matt @ MPCS EDIT: Per your changes to the post above. Edited September 22, 2004 by Matt @ MPCS Link to comment Share on other sites More sharing options...
quietus24 Posted September 22, 2004 Author Share Posted September 22, 2004 Awesome Matt, I actually wound up with the following. The Last line you added made a difference instead of relying on a variable. I got the Timerinit and Diff example from the help file and adapted it to this cause. Help file is awesome, but sometimes you need another Human Brain to put it all together. Tested with Process closing before timeout, and tested with waiting for timeout. both worked. Thanks again. ;___________________________________________________________________________________________________ _ ;Overall Variable Sets ;---------------------------------------------------------------------------------------------------- DIM $userprof = EnvGet("userprofile") DIM $windir = EnvGet("windir") ;---------------------------------------------------------------------------------------------- ; Starting Timer outside loop Dim $begin = TimerInit() Do ;Setting var(set happens each pass in loop) for time difference between this moment in script/loop and the timerinit set outside of loop. $dif = TimerDiff($begin) ; Checking difference in loop and taking action if reached. If $dif > 60000 then MsgBox (48, "ATTENTION",$dif) MsgBox (48, "ATTENTION", "Process has timed out.") ProcessClose("notepad.exe") exitloop endif ; Progress Meter ProgressOn("PSTs Processing-Please be patient.", "DO NOT INTERRUPT THIS PROCESS.", "0") For $i = 10 to 100 step 10 sleep(1000) ProgressSet( $i, $i & "") Next ProgressSet(100 , "", "") sleep(500) ProgressOff() Until Not ProcessExists("notepad.exe") 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