Results 1 to 8 of 8

Thread: Improve performance

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    Jacksonville
    Posts
    23

    Unhappy

    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

  2. #2
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    what your infinite loop use?
    show your code, maybe there's a work around

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    Jacksonville
    Posts
    23
    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

  4. #4
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    i'm saying, why it has to be infinite loop,explain!!

  5. #5
    Lively Member
    Join Date
    Aug 2000
    Location
    Ontario, Canada
    Posts
    79
    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

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    Jacksonville
    Posts
    23
    Since it is an unattended process supposed to be performed
    all the time
    thanks

  7. #7
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    SargumSingh, did you receive my email??

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    Jacksonville
    Posts
    23
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width