So, I have a main thread that captures an existing IE browser and saves the HTMLDocument in a variable. I attached an event handler to the "onload" event of this document because I need a frame that is located inside it. If I capture the frame in the main thread, everything is fine, but when the event is raised, I get an exception when I access the document:
For I = 0 To MyHTMLDocument.frames.length - 1
I have tried invoking the main thread, I tried making sure that the main document was fully loaded, but nothing seems to work. I always get a "Specified cast is not valid."
Putting MyHTMLDocument.frames into the Watch window in Visual Studio also gives the same exception "Specified cast is not valid." I'm not casting anything, am I? Some websites suggested using <STAThread()> _
which I tried for the heck, but to no avail. I also tried TryCast(MyHTMLDocument.frames, FramesCollection)
.
All I need to do is recapture a frame's document with a specific name when the document is refreshed. I assume that it's a problem with threading, but invoking doesn't even work... A funny thing is that I can access other things like Title, GetElementsByName, etc. Just not the darn frames...