Webbrowser control document_completed fires more than once

喜夏-厌秋 提交于 2019-12-25 03:16:00

问题


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.

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;
}

What am i doing wrong?


回答1:


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.

Your best solution is to add a timeout, and continue your program if you get the last DocumentCompleted event, or your timeout kicks in.



来源:https://stackoverflow.com/questions/3431451/webbrowser-control-document-completed-fires-more-than-once

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!