(WebBrowser.Document == null) throws InvalidCastException

  • Thread starter Thread starter Zytan
  • Start date Start date
Z

Zytan

if (webBrowserControl.Document == null) is throwing an
InvalidCastException.

PLEASE NOTE: ***The function being called is being called from a
thread OTHER THAN than the one that created the WebBrowser
control.*** So, I think making a delegate to invoke the function from
the proper thread will solve the problem. But, I just want to know:

Why is the above exception happening? Where is the cast?

The StackTrace for the exception (there is no InnerException):

" at
System.Windows.Forms.UnsafeNativeMethods.IHTMLDocument2.GetLocation()\r
\n at System.Windows.Forms.WebBrowser.get_Document()\r\n at MY OWN
FUNCTION... etc."

So, I guess the answer is in the above function.

Zytan
 
PLEASE NOTE: ***The function being called is being called from a
thread OTHER THAN than the one that created the WebBrowser
control.*** So, I think making a delegate to invoke the function from
the proper thread will solve the problem.

Yes, it does fix the problem, as I expected.

Zytan
 
Back
Top