开发者

WebBrowser control problem

I am using this code:

//I store the website urls in mylist
list<string> mylist=new li开发者_如何学Cst<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?


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜