views:

222

answers:

3

I am using a webBrowser control to open PDF document in winforms, it works fine but when closing the application I get sometimes an error : "The Instruction at "0x2d864aa2" referenced memory at "0x00000008". The memory could not be "read". Is there a solution for this problem?

Regards.

+3  A: 

Believe it or not, yesterday I've been banging my head against this exact same problem and here's the solution I've found. Add the following to the FormClosed event:

[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();
}

Actually it seems there's a bug in Adobe Acrobat 9.x causing this exception.

Darin Dimitrov
A: 

Thank you Darin.

I add some related links http://forums.adobe.com/thread/391780

h t t p ://stackoverflow.com/questions/1359616/axacropdflib-at-closing-problem-c

(h t t p :// www.xtremevbtalk.com/showthread.php?t=305337

Regards.

Bilel Boughanmi
A: 

Thanks Darin. works great!

Amyo Rahman