A PDF in web browser control causes a "Read Error" error when closing the application

I use the webBrowser control to open a PDF document in winforms, it works fine, but sometimes I get an error when closing the application: "The instruction on" 0x2d864aa2 "refers to the memory on" 0x00000008 ". The memory cannot be read. Is there a solution this problem?

Sincerely.

+3
source share
1 answer

Believe it or not, yesterday I hit my head about this same problem, and here is the solution I found. Add to event FormClosed:

[DllImport("ole32.dll")]
private static extern void CoFreeUnusedLibraries();

private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
    base.OnFormClosed(e);
    webBrowser1.Visible = false;
    while (webBrowser1.IsBusy)
    {
        Application.DoEvents();
    }
    webBrowser1.Dispose();
    CoFreeUnusedLibraries();
}

In fact, it seems that an error in Adobe Acrobat 9.x raises this exception.

+5

Source: https://habr.com/ru/post/1744478/


All Articles