等待web浏览器结束进程 [英] Wait for WebBrowser to finish process
问题描述
什么是处于观望到代码浏览器,然后再继续完成过程中的最佳方式?下面我尝试这个代码和进程不等待,直到其完全处理下一个环节了。
无效WaitBrowserLoading()
{
,而(webBrowser1.IsBusy)
Application.DoEvents();
的for(int i = 0; I< 500;我++)
如果(webBrowser1.ReadyState = WebBrowserReadyState.Complete!)
{
Application.DoEvents();
lblStoreID.Text =;
//System.Threading.Thread.Sleep(5);
}
,否则
中断;
Application.DoEvents();
}
执行的 导航的
或 DocumentCompleted
事件你想要什么?我怀疑后者更适合你:
在处理事件DocumentCompleted收到通知时,新的文档加载完毕。当DocumentCompleted事件发生时,新的文档被完全加载,这意味着你可以通过文件,DocumentText或DocumentStream属性来访问其内容。
块引用>
基本上你会禁用所有控件(或任何你想停止)导航前,然后重新启用它们时,事件触发。
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(); }
解决方案Do the
Navigated
orDocumentCompleted
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.
这篇关于等待web浏览器结束进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!