locked
webBrowser execution Timeout expired. The timeout period elapsed prior to completion of the operation. To avoid this error, increase the WebBrowserTimout value or set it to o (unlimited) RRS feed

  • Question

  • User-1184006624 posted

    As you notice, in my asp.net application I use a webBrowser control to search the webBrowser and extract some information using Html Agility. The problem is when I use some url, the webBrowser sends me this exception: webBrowser execution Timeout expired. The timeout period elapsed prior to completion of the operation. To avoid this error, increase the WebBrowserTimout value or set it to o (unlimited)

    I have to add something on my wwebBrowser?

    Wednesday, December 19, 2018 2:55 PM

All replies

  • User-271186128 posted

    Hi bokokibiti,

    As you notice, in my asp.net application I use a webBrowser control to search the webBrowser and extract some information using Html Agility. The problem is when I use some url, the webBrowser sends me this exception: webBrowser execution Timeout expired. The timeout period elapsed prior to completion of the operation. To avoid this error, increase the WebBrowserTimout value or set it to o (unlimited)

    Do you mean you are using this WebBrowser control? Can you share related code about how to use the webbrowser control and where you meet this error?

    Here are some related articles about using webbrowser control, you could refer to them, might be they can help you.

    Looking for webbrowser timeout if page wont load

    webbrowser class in asp.net website

    How to set timeout for webBrowser navigate event

    Best regards,
    Dillion

    Thursday, December 20, 2018 2:57 AM
  • User-1184006624 posted

    I have not been precise. What I want is just to increase the timeout of the webBrowser as the exception shows. Here is the code.

    This function is called by Ajax calls. The problem is that for some url, the code raises the exception specified above

    public IList<string> GetResponse(string url)
    {
       List<string> response=new List<string>();
       try
       {
         Thread thread = new Thread(delegate ()
         {
            var web1 = new HtmlWeb();
           var doc1 = web1.LoadFromBrowser(url, o =>
           {
                var webBrowser = (WebBrowser)o;
                      
                // WAIT until the dynamic text is set
                return  !string.IsNullOrEmpty(webBrowser.Document.Body.InnerText);
            });
    
            var nodes= doc1.SelectNodes("//a")
            foreach (var item in nodes)
            {
               response.Add(item.ParentNode.InnerHtml);
            }
         }
       }
       catch (Exception e)
    {
    throw new Exception(e.Message);
    } thread.SetApartmentState(ApartmentState.STA); thread.Start(); return response; }

    Friday, December 21, 2018 12:55 PM
  • User-271186128 posted

    Hi bokokibiti,

    According to your code, it seems that you are using HTML Agility Pack. If that is the case, you could refer to the following code to set the timeout:

    var web = new HtmlWeb();
    web.PreRequest = delegate(HttpWebRequest webRequest)
    {
         webRequest.Timeout = 4;
         return true;
    };
    var doc = web.Load("http://www.msn.com/");

    More details, please refer to these links.

    How to set HtmlAgilityPack Timeout

    How to Timeout a request using Html Agility Pack

    Best regards,
    Dillion

    Monday, December 24, 2018 5:22 AM
  • User-1184006624 posted

    Unfortunately your method does not work. He returned the same error. I even increase the value of the webRequest.Timeout 

    Monday, December 24, 2018 11:16 AM