metalaureate
asked on
Is there a non-CPU intensive way of waiting?
Dear Experts,
In VB6, is there a way of making a program wait for n seconds, without going round and round in a loop checking the system Timer, which seems to hog a lot of CPU.
Thanks
In VB6, is there a way of making a program wait for n seconds, without going round and round in a loop checking the system Timer, which seems to hog a lot of CPU.
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 everyone.
The code I posted uses a loop. If you don't want the loop, then use the DateAdd() function as I did to compute the ending time of your delay, and then check the current time in a timer event. Set the timer interval to about 250 milliseconds.
Idle_Mind
Idle_Mind
Also, my wait() sub is wrong. It shoud be:
Private Sub wait(seconds As Integer)
Dim startTime As Date
Dim endTime As Date
startTime = Now
endTime = DateAdd("s", seconds, startTime)
Do While Now < endTime
Sleep 10
DoEvents
Loop
End Sub
Sorry....I'm going to go make my pot of coffee now. =)
Idle_Mind
Private Sub wait(seconds As Integer)
Dim startTime As Date
Dim endTime As Date
startTime = Now
endTime = DateAdd("s", seconds, startTime)
Do While Now < endTime
Sleep 10
DoEvents
Loop
End Sub
Sorry....I'm going to go make my pot of coffee now. =)
Idle_Mind
ASKER
Any drawbacks the Sleep approach? Seems drastic!