I am using web browser control and trying to call function in Javascript using document.InvokeScript.
It works everywhere else in my code except at the part where i call event handler for Process.Exited.
//this function is being called from Javascript code.
public void Open()
{
//****FROM HERE TO......****
Object[] param = new Object[2];
param[0] = "play";
param[1] = "playDisabled";
webBrowser1.Document.InvokeScript("disable", param);
param[0] = "playDisabled";
param[1] = "Playing";
webBrowser1.Document.InvokeScript("setText", param);
//****THERE, INVOKESCRIPT WORKS....****
//there i open exe file...
Process GameLaunch = new Process();
GameLaunch.StartInfo.FileName = ExtractPath + gameFile;
GameLaunch.StartInfo.Arguments = ExtractPath + gameFile;
GameLaunch.EnableRaisingEvents = true;
//after its closed i call GameLaunch_Exited method.
GameLaunch.Exited += new EventHandler(GameLaunch_Exited);
GameLaunch.Start();
}
void GameLaunch_Exited(object sender, EventArgs e)
{
InvokeScript("btnReset", "#playDisabled");
}
private object InvokeScript(string name, params object[] args)
{
//here it fires an error.
return webBrowser1.Document.InvokeScript(name, args);
}
private void button1_Click_1(object sender, EventArgs e)
{
InvokeScript("btnReset", "#playDisabled");
string output = "";
int i = 0;
foreach (HtmlElement element in webBrowser1.Document.GetElementsByTagName("a"))
{
i++;
output += i+". Element: id: "+ element.Id + ", inner html: "+ element.InnerHtml + Environment.NewLine;
}
MessageBox.Show(output);
}
all i get from this code is: Specified cast is not valid.
Here are some screens:
Btw method InvokeScript works if i call it from button click handler. And doesn't if called from Exited Handler.
I'm really confused.
And the error itself:
For those who want to see my JS.
function btnReset(id){
$(document).ready(function(){
$(id).removeClass("disabled");
$(id).html("Start");
$(id).attr("id", "play");
});
}
EDIT: Exception Message:
An unhandled exception of type 'System.InvalidCastException' occurred in System.Windows.Forms.dll {"Specified cast is not valid."}
Additional information: Specified cast is not valid.
Thanks for Any help.
-Cheers
-Nick.