Yunfei.Xiao
Yunfei.Xiao

Reputation: 41

How to detect webbrowser is downloading data from target server when click an element in C#

Here is the situation: I use WebBrowser in the program, I want detect is the browser downloaded data from target server when click a html element on it.

This is what I want do:

HtmlElement element = browser.GetOneElement
element.InvokeMember("click");
if(will download data from the server?)
{
    //do something
}
else
{
    //do other thing
}

Currently, my solution is to set a flag to note is downloading, and extended OnProgressChanged of the WebBrowser control, set the flag as true there.

Here is the code:

    private bool _isInteractive;
    public bool IsInteractive
    {
        set 
        {
            _isInteractive = true;
        }
        get
        {
            Thread.Sleep(1000);
            return _isInteractive;
        }
    }

Then using it like this:

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

But I think it's not so good, even sucks. Any suggestions?

Upvotes: 0

Views: 306

Answers (1)

CodeCaster
CodeCaster

Reputation: 151664

How about the WebBrowser.IsBusy property?

Upvotes: 1

Related Questions