16

How can I solve this error?

"The requested resource is in use. (Exception from HRESULT: 0x800700AA)".

This appears while navigating to a different website using the WebBrowser control in C# .NET. Why?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Jepe d Hepe
  • 899
  • 5
  • 22
  • 42

6 Answers6

14

The WebBrowser control is considered "in use" if either a navigation action is currently being processed, or any blocking dialog from the control is currently open (including context menu, Javascript alerts, NTLM login dialog, etc.). You can use the WebBrowser.IsBusy property to detect these states.

If due to a currently incomplete navigation action, you could try to stop the current navigation (if you indeed want to stop when the page is not completed loaded) or add the new navigation to a request queue and use a timer to wait until WebBrowser.IsBusy returns false.

If instead the busy state is due to one or more open blocking dialogs, you could do the same wait technique and perhaps Messagebox.Show() the user a message that pending navigation is delayed due to an open dialog window.

Special Sauce
  • 5,338
  • 2
  • 27
  • 31
Sheng Jiang 蒋晟
  • 15,125
  • 2
  • 28
  • 46
  • 6
    How can we "stop the current navigation"? – Blaise Apr 12 '13 at 15:59
  • 2
    @Blaise Refer [WebBrowser.Stop Method](http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.stop(v=vs.110).aspx) and http://stackoverflow.com/questions/6526876/how-to-cancel-or-dispose-current-navigation-at-webbrowser-element – LCJ Mar 31 '14 at 14:28
4

I had this same issue. Calling WebBrowser.Stop() did not help, and WebBrowser.IsBusy never became false.

It turns out that if the page creates any sort of dialog (alert() popups, javascript errors, NTLM login popups etc.) you can't navigate away from the page until the dialog is closed.

My solution was to prevent the dialogs from showing in the first place. Apparently preventing all of these popups is simple; just set

webBrowser.ScriptErrorsSuppressed = true;
Community
  • 1
  • 1
BlueRaja - Danny Pflughoeft
  • 84,206
  • 33
  • 197
  • 283
  • 1
    If you prevent NTLM login popups... doesn't that prevent the user from being able to get past a proxy, for example? – Jeff B Apr 29 '14 at 21:52
  • I confirmed that setting `webBrowser.ScriptErrorsSuppressed = true` will not show the NTLM login prompt. In our case, that meant we couldn't get past to proxy to hit an external website, so this solution didn't work for us. – Jeff B May 02 '14 at 19:08
  • This error can also occur if one attempts to set `.DocumentText` while the right-clicked context menu is currently opened. You can easily check for this state by checking `WebBrowser.IsBusy` property. It does correctly return False or True depending on whether the control is ready to accept new navigation or not (respectively). – Special Sauce Oct 08 '15 at 21:37
2
bool go = false;
string SiteContent1 = string.Empty;
string SiteContent2 = string.Empty;
int index = 0;
WebBrowser wb = new  WebBrowser();

    void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {

        try
        {
            if (go)
            {
                SiteContent2 = wb.DocumentText;
                // Code to compare to contents of the webbrowser
                index++;
                go = false;
                steps = 1;
            }

            if (!go)
                {

                    if (index >= TotalSiteCount)
                    {
                        Stop();
                    }
                    else if (steps == 1)
                    {
                        wb.Navigate(UrltocompareList[index].Url1);

                    }
                    else if (steps == 2)
                    {
                        SiteContent1 = wb.DocumentText;
                        wb.Navigate(UrltocompareList[index].Url2);
                        go = true;
                    }
                    steps++;                        
                }

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);

        }

    }

UrltocompareList is a collection of 2 sites to compare.
TotalSiteCount is the number of items in UrltocompareList.
The form for this inherit IOleClientSite to remove media such as images, videos and no active X download to have a faster rendering time in webbrowser control.

I use this method instead of system.net.webclient to get the html of a webpage then compare them.
I got this error when it hits the wb.Navigate method.

Jepe d Hepe
  • 899
  • 5
  • 22
  • 42
1

An issue I ran into when running specflow tests with watin in windows 10 is that win10 by default uses MS Edge, so I had never opened IE, and when watin started it IE was stuck on the prompt for using default settings. Selecting options, closing browser and running tests again worked for me.

Just something to watch

BlackICE
  • 8,816
  • 3
  • 53
  • 91
0

This can be solved pretty easily. This error occurs when the browser commits an action while he's already performing an action. For example, you are navigating to some website while you rightclick in the web browser. To solve this, I did the follow:

//if my webbrowser isn't performing any actions
if(!myWebBrowser.IsBusy)
{
   //Navigate
   myWebBrowser.Navigate("http://www.google.com");
}
eli
  • 19
  • 1
-1

First Try

1- Please Check Navigate URL's (if you check, please check again compiled folder)

2- Delete WebBrowser Control and Add New

Me forget copy original file App.Path + "\error.html" and see this problem.

Guarantee Method

I Fix This Error in VB6

Add WebBrowserControl wb(0) (Name wb , Index=0)

And Before Ever Navigate

For i = 1 To wb.UBound

    Unload wb(i)

Next

Load wb(1)

wb(0).Visible = False

wb(1).Visible = true

wb(1).Navigate URL
Lightman
  • 1,078
  • 11
  • 22
zersina
  • 44
  • 3