BUG: Application Error When You Use DoEvents in WebBrowser ProgressChange Event (281118)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 5.5

This article was previously published under Q281118

SYMPTOMS

When you use the DoEvents function in a WebBrowser control ProgressChange event, you may receive the following application error:
The instruction at "address" referenced memory at "address". The memory could not be read.
Click on OK to terminate the application
Click on CANCEL to debug the application

RESOLUTION

There are two ways to work around this problem:
  • Use a Timer to yield to the processor.
  • Delegate the task to an ActiveX EXE component.
If you delegate the task to an ActiveX EXE component, the task can continue completely independent of your application, and the operating system takes care of multitasking and time slicing.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

  1. In Microsoft Visual Basic, create a new standard EXE project. Form1 is created by default.
  2. Under Project, click Components, and then select a reference to Microsoft Internet Controls.
  3. Add the WebBrowser control to your form.
  4. On Form1, add two command button controls (named "Back" and "Forward") and one text box control.
  5. In the code window of Form1, paste the following code:
    Private Sub Command1_Click()
    
        On Error Resume Next
        WebBrowser1.GoBack
    
    End Sub
    
    Private Sub Command2_Click()
    
        On Error Resume Next
        WebBrowser1.GoForward
    
    End Sub
    
    Private Sub Form_Load()
    
        WebBrowser1.Navigate2 "http://www.microsoft.com"
        Command1.Caption = "Go Back"
        Command2.Caption = "Go Forward"
    
    End Sub
    
    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    
        Text1.Text = WebBrowser1.LocationURL
    
    End Sub
    
    Private Sub WebBrowser1_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
    
        DoEvents
    
    End Sub
    					
  6. Run the project on a computer with Internet Explorer 5.5.
  7. Browse through a few Web pages to build up the history list.
  8. Click Back and Forward quickly to browse through the history. Eventually, you receive the above-mentioned error.
NOTE: This problem occurs both in Visual Basic Integrated Development Environment (IDE) mode and in the compiled version of the project.

REFERENCES

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

Modification Type:MajorLast Reviewed:5/11/2006
Keywords:kbBug kbnofix kbWebBrowser KB281118