Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sleep vs. Doevents

Status
Not open for further replies.

kisk

Programmer
Feb 14, 2003
21
US
I've got a pause sub that uses a timer variable with doevents to pause and loop until the time expires, but I've noticed that when the pause loop runs, the cpu usage for my app sits at close to 100%.

Would using the Sleep api do the same? If not, is there any other way to pause within a sub without using loops or timers?

Thanks,
-- kisk
 
Sleep is what you are looking for. Test it out, you'll find it useful.

There have been other discussions on Sleep, so do a search here and dig them up!

Tuna - It's fat free until you add the Mayo!
 
Yeah, but it's not exactly the same as the loop. The loop provides for message handling while waiting, whilst sleep does not (it suspends the thread).
Greetings,
Rick
 
This is how I do a pause for a number of milliseconds. It does not use doevents.

Sub mS_PAUSE(P As Long)

' This is a pause function for use in coms
' P is in milliseconds

k = Timer
Do Until Timer > k + P / 1000
Loop

End Sub

 
But it does bang CPU usage up to 100%, which is one of the things kisk wants to avoid, and does lock up your VB application until the pause is over...
 

Thread222-474702 has a small discussion on sleep/doevents

Good Luck



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top