Webbrowser控件document_completed多次触发
document_complete的事件多次触发。哪个不是那么糟糕但是我正在导航的url,从来没有被完全加载。它被触发了2/3次。
The event of document_complete fires more than once. Which isn't really that bad. But the url i'm navigating to, never gets completely loaded. It gets fired like 2/3 times.
这是我的document_completed事件:
This is my document_completed event:
private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (e.Url.AbsolutePath != this.wbrowser.Url.AbsolutePath)
return;
else
string doctext = this.wbrowser.DocumentText;
}
我做错了什么?
您将获得一个 DocumentCompleted
每帧/ iframe事件,这就是为什么有几个。如果你没有得到最后一个,那是因为一些资源仍在加载或挂起。它可以是一个图像,一个脚本文件或一些iframe。
You will get one DocumentCompleted
event per frame/iframe, that's why there are several. If you don't get the last one it's because some resource is still loading or hanging. It could be an image, a script file, or some iframe.
你最好的解决方案是添加一个超时,并继续你的程序,如果你得到最后一个 DocumentCompleted
事件,或您的超时踢。
Your best solution is to add a timeout, and continue your program if you get the last DocumentCompleted
event, or your timeout kicks in.