views:

75

answers:

0

The following code,

public class IEBrowser
{
    SHDocVw.InternetExplorer view = new SHDocVw.InternetExplorer();

    public void Display(String url)
    {
        // make sure it's open
        if (!view.Visible) view.Visible = true;

        view.Navigate(url);
    }

}

works as expected on the first call to Display. However, the next time it's called it crashes on this line:

if (!view.Visible) view.Visible = true;

with this error:

The object invoked has disconnected from its clients. (Exception from HRESULT: 0x80010108 (RPC_E_DISCONNECTED))

Anyone one know how to solve this problem? I'm trying to open one instance of IE and use it throughout the life of my application to display information.

One thought I had is that perhaps this could be some kind of threading error. It is possible that Display might be getting called from a thread other than the one it was created on. Could that have anything to do with it?

Thanks for your insight!

EDIT: I'm using .NET 4.0, which since this uses COM, may be important information!

EDIT 2: After playing around with the error most of the afternoon I've determined the error is not related to threading. It happens when displaying a local html file. After displaying a local HTML file the next call to Display() crashes the program. However it will work all day with web based urls with no problems... Anyone have any ideas?