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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
Private Function NonStopLoop() as boolean
Dim i As Integer
Do While True And Not(Timeout)
i = 1
Loop
Return Timeout
End Sub