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"?