An inexplicable exception message...
Use this function to call the JS script in the webbrowser control:
Webbrowser. Document. invokescript ("function name", parameter list );
However, a very difficult problem encountered in the afternoon is that such an inexplicable exception will be thrown during the call:
System. invalidcastexception not handled Message = "the specified conversion is invalid. " Source = "system. Windows. Forms" Stacktrace: In system. Windows. Forms. unsafenativemethods. ihtmldocument2.getlocation () In system. Windows. Forms. webbrowser. get_document () In ipmessagernet. UI. Controls. Chat. ieview. ietabpage. commander_textmessagereceived (Object sender, messageeventargs E) In system. eventhandler '1. Invoke (Object sender, teventargs E) Innerexception: |
...... Inexplicable ~ That's amazing.
It was originally with a parameter. It was thought that there was a problem with the parameter. It was found that the type and number of parameters were incorrect and depressing. Later, it was found that no parameters were the same and incorrect.
After more than half an hour of fighting, I finally found the cause:Called across threads.
Simply put, when the above function is called, it is not the main interface thread (because it is a function callback), and the result reports such an inexplicable error.
Solution: Use the delegate to put the function in the main thread for calling.