Pause / Sleep / Timer ?

chrishan
09-17-2002, 03:11 PM
I currently use a function:

Public Function pause(Seconds)
Dim Start

Start = Timer ' Set start time.

Do While Timer < Start + Seconds
DoEvents ' Yield to other processes.
Loop
End Function

However the problem I see is this racks up the cpu to 100%. I then tried using sleep:

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

however this tells the whole app to sleep and I am unable to use any of the controls.

My question is does anyone have a suggestion on how to pause execution for X seconds, allowing for other controls to be hit, which doesnt suck the cpu dry?

Thanks :)

Iceplug
09-17-2002, 03:13 PM
Have you tried adding a DoEvents before your sleep call?
You could also partition your sleep calls to
DoEvents
Sleep 100
DoEvents
Sleep 100
etc...
I haven't tried it, but it should work, somewhat... :).

chrishan
09-17-2002, 03:15 PM
I have tried using the DoEvents before the sleep however once sleep occurs it locks the controls and if I was to space them apart like that I would have miliseconds to hit the control before it was locked again. Thanks for the suggestion :)

BillSoo
09-17-2002, 03:21 PM
Personally, I don't see the problem with running the CPU up to 100%.... after all, if you have any other process running, it will get it's share of time anyways so all you are doing is using up time that would be wasted.

But if you insist, you can try using the WaitForSingleObject function....I haven't used it myself...

chrishan
09-17-2002, 03:23 PM
Thanks, I will give that a try. Personally I am not to concerned about what the montor shows being used since it has little affect on the machine, however one of the managers here at my work is having a fit about seeing the cpu at 100% for any given period of time, no matter how much I explain it isnt taking away from the other applications. Oh well what can you do Quit :D

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum