0

我有这个代码片段需要检索 iframe 的文档对象并将其保存在一个对象中。

//just a wrapper object to store the document object   
DocObj obj = new DocObj(HtmlDoc);

ManualResetEvent aDoneEvents = new ManualResetEvent(false);
string errorMessage = "";
Thread aThread = new Thread(() =>
{
    try
    {
        //finding the iframe element in the current document
        IHTMLElement IElem = LocatorBuilder.GetLocator(Target)
                   .Find(this.HTMLDoc);

        obj.HTMLDoc = (IElem as HTMLIFrame).document as HTMLDocument;

    }
    catch (Exception e)
    {
        errorMessage = e.Message;
    }
    aDoneEvents.Set();
});

aThread.SetApartmentState(ApartmentState.STA);
aThread.IsBackground = true;
aThread.Start();
aDoneEvents.WaitOne();
if (errorMessage != "")
{
    throw new Exception(errorMessage);
}
HtmlDoc = obj.HTMLDoc;

但是当我尝试检索新的文档对象时,我在最后一行得到了这个异常:

函数评估已禁用,因为之前的函数评估超时。您必须继续执行才能重新启用函数评估

4

1 回答 1

0
mshtml.IHTMLDocument3 doc3 =   (mshtml.IHTMLDocument3)webBrowser.Document.DomDocument;
mshtml.IHTMLFrameBase2 frame = (mshtml.IHTMLFrameBase2)doc3.getElementById("iframe_name");
if (frame != null)
{
    mshtml.IHTMLWindow2 w2 = (mshtml.IHTMLWindow2)frame.contentWindow;
    doc3 = (mshtml.IHTMLDocument3)w2.document;
}
于 2015-02-13T11:17:09.637 回答