Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在单击C中的元素时检测webbrowser正在从目标服务器下载数据#_C#_Webbrowser Control - Fatal编程技术网

C# 如何在单击C中的元素时检测webbrowser正在从目标服务器下载数据#

C# 如何在单击C中的元素时检测webbrowser正在从目标服务器下载数据#,c#,webbrowser-control,C#,Webbrowser Control,情况是这样的:我在程序中使用WebBrowser,我想在单击目标服务器上的html元素时检测浏览器从目标服务器下载的数据 这就是我想要做的: HtmlElement element = browser.GetOneElement element.InvokeMember("click"); if(will download data from the server?) { //do something } else { //do other thing } 目前,我的解决方案是

情况是这样的:我在程序中使用
WebBrowser
,我想在单击目标服务器上的html元素时检测浏览器从目标服务器下载的数据

这就是我想要做的:

HtmlElement element = browser.GetOneElement
element.InvokeMember("click");
if(will download data from the server?)
{
    //do something
}
else
{
    //do other thing
}
目前,我的解决方案是将标记设置为note is downloading,并在
WebBrowser
控件的扩展
OnProgressChanged
中将标记设置为true

代码如下:

    private bool _isInteractive;
    public bool IsInteractive
    {
        set 
        {
            _isInteractive = true;
        }
        get
        {
            Thread.Sleep(1000);
            return _isInteractive;
        }
    }
然后像这样使用它:

HtmlElement element = browser.GetOneElement
browser.IsInteractive = false;
element.InvokeMember("click");
if(browser.IsInteractive)
{
    //do something
}
else
{
    //do other thing
}

但我觉得不太好,甚至很糟糕。有什么建议吗?

该属性如何?

这里是源代码注释获取的值,该值指示System.Windows.Forms.WebBrowser控件当前是否正在加载新文档。我想应该先下载数据,然后再加载文档,对吗?所以我们应该在点击后等待一段时间,然后检测是否正忙,应该等待多长时间?PS:加载时将设置为falsecompleted@Yunfei.Xiao不,你不应该等待,而且绝对不是你猜测浏览器需要的随机数量。我不知道你到底想做什么。您想检测浏览器是否正在下载数据,对吗?这就是“加载新文档”,所以IsBusy将是真的。是的,你是对的。单击后,它不会立即变为真。您可以这样说:HtmlElement元素=browser.GetOneElement.InvokeMember(“单击”);如果(browser.IsBusy){//do something}其他{//do other thing}OnDocumentCompleted事件在这种情况下是否有用,而不是等待/轮询IsBusy进行更改?