Results 1 to 8 of 8

Thread: Is there something less Processor intensive then DoEvents?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    13

    Is there something less Processor intensive then DoEvents?

    I have a program that needs to wait for a web page to load completely. I do this by setting a global boolean variable when the document = DocumentComplete.

    VB Code:
    1. Public Function GotoWebPage(vWebPage as string) as boolean
    2.  
    3. wb.Navigate = vWebPage
    4. wpReadyFlag = False
    5.  
    6. Do While wpReadyFlag = False
    7.     DoEvents
    8. Loop
    9.  
    10. End Function
    11.  
    12. Private Sub wb_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    13.     If wb.ReadyState = READYSTATE_COMPLETE Then
    14.         wpReadyFlag = True
    15.     End If
    16. End Sub

    When this runs (and it runs many many times) the processor spikes to 100% for the duration of the page load. Is there something else I can do instead of "DoEvents"?
    It's All Good.

  2. #2
    Addicted Member
    Join Date
    May 2004
    Location
    China
    Posts
    228
    Call the sleep api instead.

    Here:

    VB Code:
    1. ''Put the app to sleep for a bit...
    2. 'http://www.vbexplorer.com/VBExplorer/time.asp
    3. Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    4.  
    5. 'In your loop
    6. Do While wpReadyFlag = False
    7. Sleep 1000 '1 second
    8. Loop
    Last edited by madjon; May 25th, 2004 at 02:00 PM.

  3. #3
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    Just put your code in the DownloadComplete event
    \m/\m/

  4. #4
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343
    I'd use the Sleep API, but I'd do it like this:
    Code:
    Do While wpReadyFlag = False
        DoEvents ' you still want to check those events :)
        Sleep 10 ' better responce time but still saves the CPU
    Loop

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    13

    Aye, all good idea's but...

    I've tried them all.. If I put my code in the document_complete sub it get's WAY out of hand trying to figure out what page I'm on. It sort of works but there is a lot more going on then I can put here.. SleepEX puts my whole application to bed when there are many other parts of the application running different items and other browser windows.

    Thanks for the suggestions tho I do appreciate it, and I should have mentioned that I've tried those before.. my bad.

    Any othere ideas?
    It's All Good.

  6. #6
    Addicted Member
    Join Date
    May 2004
    Location
    China
    Posts
    228
    You could post your project for us to look at.

  7. #7
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343
    It sounds like you have another loop somewhere

  8. #8

    Thread Starter
    New Member
    Join Date
    Jan 2004
    Posts
    13
    Madjon, unfortunately I've put as much code here as I could about the problem and I can't put the big picture up for there are some trade sercrets (I'm not being funny ) that I don't need to get fired over... I will try to strip all the business stuff out and put up the basics... Thanks

    Longwolf - The only loops running at the time are waiting for the web page with the doEvents. When I read this I went back and checked... good idea tho..

    Thanks
    CrazyVBr
    It's All Good.

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