Webbrowser控件document_completed多次触发 [英] Webbrowser control document_completed fires more than once

查看:137
本文介绍了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.

这篇关于Webbrowser控件document_completed多次触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆