问题
What's the best way to code in a wait for the browser to finish process before continuing? I tried this code below and the process is not waiting till its complete before processing the next link.
void WaitBrowserLoading()
{
while (webBrowser1.IsBusy)
Application.DoEvents();
for (int i = 0; i < 500; i++)
if (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
lblStoreID.Text = "";
//System.Threading.Thread.Sleep(5);
}
else
break;
Application.DoEvents();
}
回答1:
Do the Navigated or DocumentCompleted events do what you want? I suspect the latter is more appropriate for you:
Handle the DocumentCompleted event to receive notification when the new document finishes loading. When the DocumentCompleted event occurs, the new document is fully loaded, which means you can access its contents through the Document, DocumentText, or DocumentStream property.
Basically you'd disable all the controls (or whatever you want to "stop") before navigating, then re-enable them when the event fires.
来源:https://stackoverflow.com/questions/7295560/wait-for-webbrowser-to-finish-process