views:

46

answers:

2

I am using this code:

//I store the website urls in mylist
list<string> mylist=new list<string>();     

foreach(string webname in mylist)
{
    wbmain.navigate(webname);
}

But there is a problem in the code is the wbmain.navigate the first url and doesn't wait for first url to open and it opens second ..........and it shows the last url.

Finally I see the last page.

How can I if check the first url is opened and wait for 15 sec and open the second page?

+1  A: 

You could try:

List<string> myList = new List<string>();

foreach(string webName in myList)
{
    wbmain.navigate(webName);

    // Sleep for 15 seconds.
    System.Threading.Thread.Sleep(15000);
}

...the example assumes you're working in WinForms.

There is a better (and correct) way to wait until the page has loaded. The WebBrowser control has a DocumentCompleted Event that you could use to reload a new address each time the current page finishes loading. Check the link for the MSDN documentation:

WebBrowser.DocumentCompleted - MSDN

Justin Niessner
Thread.Sleep would block the webbrowser because it is trying to notify the main thread of the Navigating event, and the notification is blocked by Thread.Sleep.
Sheng Jiang 蒋晟
@Sheng The example was quick and off the top of my head which is why I posted the better (and correct) way to wait for the page to finish loading.
Justin Niessner
A: 

You could also follow this example and open each in a new tab.

taylonr