Issue
m quite new with webview2 since I found it as an alternative to what I was using before which is Cefsharp (since it does not support loading videos from facebook). With a simple project of webview2 form with a button that shows another form with webview its working as intended (showing facebook with video).
Now my roadblock is im trying to open the webview2 form through a websocket message receive but I still have no luck loading the webview2 and only shows the black form. I’m using Application.Run(webview2form) to load the webview winform called through websocket since webview2form.show does not work at websocket. Any suggestions regarding the issue? Thanks.
Im quite new with webview2 since I found it as an alternative to what I was using before which is Cefsharp (since it does not support loading videos from facebook). With a simple project of webview2 form with a button that shows another form with webview its working as intended (showing facebook with video).
Now my roadblock is im trying to open the webview2 form through a websocket message receive but I still have no luck loading the webview2 and only shows the black form. I’m using Application.Run(webview2form) to load the webview winform called through websocket since webview2form.show does not work at websocket. Any suggestions regarding the issue? Thanks.
Here is the code sample:
private void ReceiveMsgFromWebsocket(string message) {
switch (message)
{
case "Web": //if i receive web msg from websocket switchtoweb
SwitchToWeb();
break;
}
}
Here is my current code for SwitchToWeb()
private void SwitchToWeb(){
Mainform mf = new MainForm()
mf.CallWeb();
}
Code for CallWeb()
void CallWeb(){
WebViewForm dw = new WebViewForm ();
wf.InitWebview(url);
wf.Show();
}
For what i currently achieve, Im able to display the form but not the webview. But when i tried to call CallWeb() via keypress i dont have problem showing the form and loading the webview
Solution
So far I figured it out by calling by using invoke
Invoke(new Action(() => CallWeb());
Answered By – Nic
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0