C#

2012-10-05 6 views
0

iframe 문서 개체 가져 오기 iframe의 문서 개체를 검색하여 개체에 저장해야하는이 코드 단편을 가지고 있습니다.C#

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

하지만 난 마지막 줄에이 예외 얻을 새 문서 객체를 검색하려고하면 이전 기능 평가 시간이 초과하지 않도록

기능 평가. 당신은 다시 활성화 기능 평가

+0

는 당신이 어딘가에 중단 점을 설정하고 디버깅을 실행을 계속해야합니까? –

+0

aDoneEvents.WaitOne()을 사용하면 안됩니다. aDoneEvents.Set();을 호출하기 전에 호출되어야합니다. (스레딩 멍청한 놈에게서) –

+0

어떤 버전의 .NET을 사용하고 있습니까? – casperOne

답변

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

텍스트 설명을 추가하십시오. – Mysterion