1

VS 10, WinFormApp

I have a list of url's. I am trying to navigate to the URL's one by one. After completing the load of the document of a page, then the integrated webbrowser will navigate to the next URL.

Here is some code:

private void btnHit_Click(object sender, EventArgs e)
    {
        webBrowser1.Navigate(lstUrls[counter].url);

    }

 private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        if (e.Url != webBrowser1.Url)
        {
            lblStatus.Text = "Page is loading....";
            lblStatus.ForeColor = Color.Red;
            return;
        }
        else
        {                
            funcMethod();               

        }
    }

 public void funcMethod()
    {
        lblStatus.Text = "Page is loaded";
        lblStatus.ForeColor = Color.Green;            

        try
        {
            webBrowser1.Document.Focus();
            webBrowser1.Navigate(lstUrls[++counter].url);

        }
        catch { }
    }

The problem is, when I debug for each element line by line, it works for all(100+) items in the List of URL's. but when I just press the btnHit, then sometimes it loads 2/3/4/5/.. number of urls. and stop loading further. In that time, If I hit the btnHit again, the process starts and same thing happens as before.

What am I missing?

Abdur Rahim
  • 3,975
  • 14
  • 44
  • 83

0 Answers0