开发者

PDF document in webBrowser control cause 'The memory could not be "read"' error when closing application

开发者 https://www.devze.com 2022-12-30 00:43 出处:网络
I am using a webBrowser control to open PDF document in winforms, it works fine but when closing the ap开发者_StackOverflow社区plication I get sometimes an error : \"The Instruction at \"0x2d864aa2\"

I am using a webBrowser control to open PDF document in winforms, it works fine but when closing the ap开发者_StackOverflow社区plication 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消