Loading Webpage - Wait until page is loaded
-
I am using this code for check webbrowser's activity
while (wbr.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }
But when I am usingheForm.InvokeMember("submit");
which submits a form on a webpage, ReadyState will not be activated or changed. Also the IsBusy flag doesn't change. -
I am using this code for check webbrowser's activity
while (wbr.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }
But when I am usingheForm.InvokeMember("submit");
which submits a form on a webpage, ReadyState will not be activated or changed. Also the IsBusy flag doesn't change.I wouldn't do that. Application.DoEvents is terribly inefficient, causes many allocations and can result in unexpected scenarios. Instead, just listen for the wbr.Navigating event, which will tell you when the browser's busy. I believe there's a DocumentCompleted event to tell you when the document is fully loaded.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Bought a House! Judah Himango
-
I wouldn't do that. Application.DoEvents is terribly inefficient, causes many allocations and can result in unexpected scenarios. Instead, just listen for the wbr.Navigating event, which will tell you when the browser's busy. I believe there's a DocumentCompleted event to tell you when the document is fully loaded.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Bought a House! Judah Himango
-
Hi Judah, thx for reply and this tip. But additionally this won't work with InvokeMember. After firing this code line the application doesn't recognize browser activity.
Not sure if this is what you are looking for. The following example shows some of my code I've used where I have a timer event handler function call this piece of code every second. Without the if statement this would cause problems because the page doesn't always load in the browser at the same speed - it will make the program stop responding. But with the if statement this checks and makes sure the WebBrowser object is not loading anything at the moment and if it is, it doesn't execute the code (doesn't load anything else - until the statement is true): if (webBrowser1.IsBusy == false && webBrowser1.IsOffline == false) { webBrowser1.Url = new Uri(strUrl); } Let me know if I can help further.
-
Not sure if this is what you are looking for. The following example shows some of my code I've used where I have a timer event handler function call this piece of code every second. Without the if statement this would cause problems because the page doesn't always load in the browser at the same speed - it will make the program stop responding. But with the if statement this checks and makes sure the WebBrowser object is not loading anything at the moment and if it is, it doesn't execute the code (doesn't load anything else - until the statement is true): if (webBrowser1.IsBusy == false && webBrowser1.IsOffline == false) { webBrowser1.Url = new Uri(strUrl); } Let me know if I can help further.
Hi peshkunta, After InvokeMember (new in .NET Framework 2.0) -> IsBusy = false IsOffline = false that's the problem (tested with your code above as check process) InvokeMember fire a method of the selected HTML element. I loaded a FORM tag and after submitting it, a new webpage is loaded again. But if I am in debugging mode and go to the line after InvokeMember I wait a moment and then it works, because the browser don't fire the flag immediately.