InvalidCastException未处理webBrowser1

时间:2017-01-11 00:13:57

标签: c# html-agility-pack

     public delegate string GetStringHandler();

    public string GetDocumentText()
    {
        if (InvokeRequired)
        {
            return Invoke(new GetStringHandler(GetDocumentText)) as string;
        }
        else
        {
            if (this.webBrowser1.InvokeRequired)
            {

            }
            else
            {
                return webBrowser1.Document.Body.OuterHtml;
            }
        }
    }

我在else括号下的第二次返回时得到错误。

如何调用webBrowser1?

我错过了什么?

1 个答案:

答案 0 :(得分:2)

public delegate string GetStringHandler();

public string GetDocumentText()
{
    if (InvokeRequired)
    {
        return Invoke(new GetStringHandler(GetDocumentText)) as string;
    }
    else
    {
        return webBrowser1.Document.Body.OuterHtml.ToString();
    }
}