So basically I'm trying to fire WebBrowser's RaiseEvent from console applicaton but it does not work. In WinForms project it works well, so I'm just wondering what I have to do to make it work in console app. Is this even possible?
This is how I create thread for my WB
private static Thread runBrowserThread(int mCandidatePosition)
{
var wbThread = new Thread(() => {
mClient = new WebClient();
mainWebBrowser.ScriptErrorsSuppressed = true;
mainWebBrowser.AllowNavigation = true;
mainWebBrowser.DocumentCompleted += MainWebBrowser_DocumentCompleted;
mainWebBrowser.Navigate(new Uri(xxx));
Application.Run();
});
wbThread.SetApartmentState(ApartmentState.STA);
return wbThread;
}
and this is how I try to do it:
HtmlElement selectType = gDoc.GetElementById("xxx");
selectType.RaiseEvent("onchange");
The code above work well in WinForms project, but in console application nothing happens. Additionally, InvokeScript works well so it is a bit weird to me.
You should use the
InvokeMember()
method of theHtmlElement
: