WebBrowserDocumentCompletedEventArgs Not Reached inside While Loop
- by user3715962
I am trying to use the WebBrowserDocumentCompletedEventHandler inside of a while loop but when the code executes the WebBrowserDocumentCompletedEventArgs is never reached.
Can somebody tell me what I am doing wrong?
int year = 1900;
int currentYear = 2014;
private void button1_Click(object sender, EventArgs e)
{
while (year < currentYear)
{
WebBrowser wb = new WebBrowser();
wb.Navigate("http://myurl.com/list/" + year.ToString());
year++;
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
}
}
void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//Code is not reaching here
MessageBox.Show("Test");
}