1
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        for (int i = 0; i < urlLinks.Count; i++)
        {
           string NavigateUrl = "http://abc.co.in" + urlLinks[i].ToString();
            webBrowser1.AllowNavigation = true;
            webBrowser1.ScriptErrorsSuppressed = true;
            webBrowser1.Navigate(NavigateUrl);
            HtmlElement htm = webBrowser1.Document.Body;
            }
}

I have above code where I loop through urls and read through the content however when loop through it does not navigate to other url, it only loads first url throughout the loop.Is there any way to make webbrowser navigate to all the list of url. I think it is happening as for loop is much faster. I also tried to chek if e.Url.ToString() and urlLinks[0].ToString() is same but still it does not make any difference to the output. I get the result for number of times it loops.

Any help would be appreciated.

LearningPal
  • 554
  • 2
  • 12
  • 27
  • 2
    There are a few questions covering this scenario already [1](http://stackoverflow.com/questions/26912905/c-sharp-webbrowser-in-a-loop) / [2](http://stackoverflow.com/questions/30214283/how-to-use-web-browser-control-in-for-loop) / [3](http://stackoverflow.com/questions/18303758/can-i-wait-for-a-webbrowser-to-finish-navigating-using-a-for-loop). Essentially you don't need a loop inside the DocumentCompleted event. Ask for the first URL, when DocumentCompleted fires do your processing and increase your index, then ask for the next URL until you have none left. – Equalsk Sep 27 '16 at 10:20

1 Answers1

1

After this line (after each navigation in webBrowser)

 webBrowser1.Navigate(NavigateUrl);

webBrowser1_DocumentCompleted function will be called.Better not do this in DocumentCompleted event.

Gokul
  • 788
  • 2
  • 12
  • 30