-
I have a VB application which has an inifinte loop. The loop may not be doing anything at times but consumes upto 99% CPU during that time. Even if I have Sleep/DoEvents the CPU consumption is upto 65 - 70%.
Please let me know how to make programs mor CPU efficient
to improve performance
Thanks
-
what your infinite loop use?
show your code, maybe there's a work around
-
My loop is
Do While (True)
Sleep (10)
'some processing
Loop
Public Sub Sleep(PauseTime As Integer)
Dim start As Double
start = Timer ' Set start time.
Do While Timer < start + PauseTime
DoEvents ' Yield to other processes.
If Timer < 50 Then
start = Timer
End If
DoEvents
Loop
End Sub
while it is processing the CPU is 2 or 3. But when idle it consumes all the CPU
Thanks
-
i'm saying, why it has to be infinite loop,explain!!
-
Try this:
Code:
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Private Sub DoInFiniteLoop()
Do While (True)
DoEvents
Sleep (10)
'some processing
Loop
End Sub
-
Since it is an unattended process supposed to be performed
all the time
thanks
-
SargumSingh, did you receive my email??
-
I'm now using the sleep API instead of VB Timer function.
It just works great. Now the app really looks like sleeping
consuming 00 CPU.
Thanks