Link to home
Start Free TrialLog in
Avatar of william007
william007

asked on

Stop the execute of command if it execute more than 3 seconds

Is it possible to stop the execute of a command if it executes more than 3 seconds?
If the command executes successfully, prompt a "Command execute success"
If the command executes failed, prompt a "Command execute failed"?

eg
Private Sub Command1_Click()
Call NonStopLoop
'if it executes more than 3 seconds, stop it. This is just an example, and obviously it won't stop within 3 seconds.
End Sub

Private Sub NonStopLoop()
Dim i As Integer
Do While True
    i = 1
Loop
End Sub
SOLUTION
Avatar of PreachDotNet
PreachDotNet

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PreachDotNet
PreachDotNet

Sorry Theres the return true or false bit

Private Function NonStopLoop() as boolean
Dim i As Integer
Do While True And Not(Timeout)
    i = 1
Loop
Return Timeout
End Sub
Avatar of william007

ASKER

Thanks preachDotNet,

Can we assume that the NonStopLoop is a API function, and we can't change the code of it,
is it possible to interfere to command execution just in Command1_Click?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, this is a general question,
I have post my real problem here,
https://www.experts-exchange.com/questions/21785775/How-to-deal-with-remote-directory-not-exist.html
Since if the remote server doesn't exist, the problem line will run forever, I wish to do something to let it time out for 3 seconds,
but now seems like I need to change my strategy.