0

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?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

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 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.
0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.