Hi.
I have an application that navigates between the framesets
of a web page. To do this, I have used the
Document_Complete event handler as follows:
private void axWebBrowser1_DocumentComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
IHTMLDocument2 doc = (IHTMLDocument2)
this.axWebBrowser1.Document;
IHTMLFramesCollection2 frames = HTMLDocument.frames;
....
....
}
Ok, that works fine. Now, i have moved that code
(cut&paste, without changing anything)to ahother function
in other thread. This looks like:
private void axWebBrowser1_DocumentComplete(object sender,
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
navigating=false;
}
public void nav()
{
navigating=true;
object loc = url;
object null_obj_str = "";
System.Object null_obj = 0;
this.axWebBrowser1.Navigate2(ref loc , ref
null_obj,ref null_obj, ref null_obj_str, ref null_obj_str);
...
...
// waits to Document_Complete event
while(navigating)
Thread.sleep(500);
...
...
// the same code
IHTMLDocument2 doc =(IHTMLDocument2)
this.axWebBrowser1.Document;
IHTMLFramesCollection2 frames = HTMLDocument.frames;
...
}
Now, the line with IHTMLFramesCollection... throws an
exception:
at mshtml.HTMLDocumentClass.IHTMLDocument2_get_frames ()
at prueba.nav() in c:\cs\prueba\prueba.cs:line 147
System.InvalidCastException: Interfaz no compatible
(i work with the spanish VS.NET).
What's wrong? I have also tried to stop the thread over a
minute to ensure that the page loads completely, but with
the same result. Why i get an InvalidCastException if i
have cut&paste the code from one function to other?
Thanks.