0

I have this code snippet that needs to retrieve the document object of an iframe and save it in an object.

//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;

But when I try to retrieve the new document object I get this exception on the last line:

Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation

stuartd
  • 70,509
  • 14
  • 132
  • 163
Yengibar
  • 31
  • 1
  • 3

1 Answers1

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;
}