Closed globeport closed 8 years ago
Just to add, there's nothing special about navigating to the Monaco editor. If I navigate to www.google.com the same thing happens. I'm going to take the example UWP project posted here, and try the above just to exclude anything particular to my project setup.
Yep I can replicate this with the UWP example.
Steps:
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
WebView.DOMContentLoaded += WebView_DOMContentLoaded;
WebView.Navigate(new Uri("http://www.google.com"));
}
private void WebView_DOMContentLoaded(WebView sender, WebViewDOMContentLoadedEventArgs args)
{
new ChakraHost.ChakraHost().init();
}
}
This looks like a significant problem unless I'm missing something? Thanks.
Error is normal since WebView also creates the Runtime.
OK so two runtimes. But they don't operate in isolation?
One runtime, multiple context ?
OK, to rephrase, how do I use the WebView and Chakra Engine together without raising ''Runtime is active on another thread' errors. :) If I'm working with the Chakra engine yes I can create multiple contexts. The problem is creating contexts in the first place if I have a WebView active which seems to be hogging the runtime.
Didn't use WebView. If you are on the same thread with WebView (which is IIRC to be main thread??) You may get the active context by calling JsGetCurrentContext
and using that Context, you may grab the Runtime objectJsGetRuntime
.
Just a suggestion. Didn't try it.
This assumes a shared runtime though. I thought the whole point was to be able to create separate isolated runtimes. Surely if I explicitly create a new runtime this should not interact with the runtime created by the WebView. Anyway I'll investigate a bit more, thanks.
Great. Please share your experiences back. It may help others :) Keeping this open for a while then.
Please keep this open. I haven't yet found a way to use the WebView control and Chakra engine together in a UWP app. This seems like a significant issue. Hopefully someone will be able to shed some light.
Thanks
/cc @munyirik ?
OK I think I've found the problem. In the example above I'm creating a runtime on the UI thread (the same thread as the WebView).
If I do one of the following I can successfully create a new context on a new runtime.
Either
1) Run the WebView on a separate thread ( some limitations)
2) Create the Chakra runtime on a separate thread. e.g. Task.Run(()=>new ChakraHost.ChakraHost().init()) in the above example;
Phew. Happy to close :)
Perfect!
I have a UWP app and a page with a WebView control.
The WebView points to a version of the Monaco Editor (https://github.com/Microsoft/monaco-editor) embedded in my app:
WebViewEditor.Navigate(new Uri("ms-appx-web:///Monaco/index.html"));
All works well.
However if I then try to use the Chakra engine, I immediately get 'wrong thread' exceptions.
The following will fail on the second line attempting to create a new context:
var runtime = JavaScriptRuntime.Create(); var context = runtime.CreateContext();
If I remove the WebView navigation above, the chakra engine functions fine.
I wouldn't have expected there to be any interaction? I would have expected a new chakra runtime to operate in isolation and have no threading issues when used in combination with a WebView control. Very odd. Any ideas?
Thanks, Stuart