Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I'm working on WPF application that there are custom UI Threads. When I started WebView2, why the UI Threads replaced by Edge sub-processes? #520

Closed
aesteves900 opened this issue Oct 12, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@aesteves900
Copy link

aesteves900 commented Oct 12, 2020

Description
I'm working on WPF application that there are custom UI Threads. When I started WebView2, why the UI Threads replaced by Edge sub-processes?

It's a Trade application (WPF-Xamarin, .NET Core 3.1) that has intensive UI updates. There are two components that need to use WebView. We using CefSharp and a custom BrowserSubprocess to avoid this replacement. But we need to use a WebView from a big player like Microsoft because there are concise updates and continuation of the WebView product.

In the Login process, we use a WebView in a Custom Renderer:

                   var core = await CoreWebView2Environment.CreateAsync();
                    var control = new WebView2();               
                    control.Source = new Uri(url);
                    base.SetNativeControl(control);

This code above works perfectly but replaces all custom UI Threads. Please take a look at the screencaps.

Version
SDK: e.g. 0.9.628-prerelease
Runtime Browser channel and version, e.g. Canary Beta
Framework: WPF, .NET Core 3.1, Xamarin 4.7.0.1179.
OS: Win10, Enterprise

Repro Steps

Screenshots
1 - Open the application, there re 3 UI Threads, the first is Mainwindow and two custom threads.

image

2 - After opening a WebView and just navigate to Login URL, all the UI Threads will be reconfigured, why?

The core:
var core = await CoreWebView2Environment.CreateAsync();
var control = new WebView2();
control.Source = new Uri(url);
base.SetNativeControl(control);

image

@aesteves900 aesteves900 added the bug Something isn't working label Oct 12, 2020
@aesteves900 aesteves900 changed the title I working on WPF application that there are custom UI Threads. When I started WebView2, why the UI Threads replaced by Edge sub-processes? I'm working on WPF application that there are custom UI Threads. When I started WebView2, why the UI Threads replaced by Edge sub-processes? Oct 12, 2020
@champnic
Copy link
Member

Hi @aesteves900, thanks for the report!

If I'm understanding correctly from the screenshots, those are processes that are being created, not threads. And they aren't all displaying UI. WebView will create and use multiple processes for various aspects of it's execution, including main browser process, GPU process, and renderer processes per site. You can read more about it here:
https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/process-model

I wouldn't expect it to "replace" or close any of the existing processes though. Is that what you are seeing? If possible, can you share some sample code/app that demonstrates this?

@aesteves900
Copy link
Author

aesteves900 commented Oct 12, 2020

Hello, @champnic! Thank you for answer my question!

I created the Thread according to Microsoft documentation like this:

using NativeWindow = System.Windows.Window;

Thread newWindowThread = new Thread(() =>
{
container = this.CreateWindow(componentTitle);

                UiContainer<NativeWindow> uiContainer = new UiContainer<NativeWindow>(container, new UiObserver(), instanceId);

                uiContainer.SetComponentInfo(component);

                this.Threads.AddOrUpdate(instanceId, uiContainer, (key, oldValue) => uiContainer);

                container.Show();
                Dispatcher.Run();
            });


            newWindowThread.SetApartmentState(ApartmentState.STA);                
            newWindowThread.Name = componentTitle;
            newWindowThread.Start();

private NativeWindow CreateWindow(string componentTitle)
{
var container = new NativeWindow()
{
Width = 0,
Height = 0,
WindowStyle = WindowStyle.None,
ShowInTaskbar = false,
ShowActivated = false,
Title = componentTitle,
AllowsTransparency = true,
Background = System.Windows.Media.Brushes.Transparent,
FocusVisualStyle = null
};

        return container;
    }

My UI Thread uses minimal resources of System.Windows.Window, like you, see above. This code creates a WPF UI Thread and receives out-of-process all of PropertyChangeEvents from ViewModel. This solution allows thousands of UI updates in seconds.

When I started the WebView2 via CoreWebView2Environment.CreateAsync...causes the effect that I showed up on screenshot 2.
But the property change still working in the background.

Is it possible to start the msedgewebview2.exe as a background process via CoreWebView2Environment.CreateAsyn without any change on the Main Process on the Task Manager?

Just to let you all know the CefSharp create creates a BrowserSubProcess that's receive render actions and allows you to customize and extend the default implementation:

image

My console example from CefSharp. It running out-of-process from the Main WPF Application.

image

Shows in the task manager as above.

@champnic
Copy link
Member

Thanks for the additional info! Our process model is based on Edge/Chromium's, and matches the sandboxing model described in CEF: https://bitbucket.org/chromiumembedded/cef/wiki/SandboxSetup.md#:~:text=The%20Chromium%2FCEF%20multi-process%20model%20uses%20separate%20processes%20for,access%20to%20the%20file%20system%20or%20network%20stack.
We don't currently have plans to support a single process model (which seems to be what CEF's BrowserSubProcess implements) as this comes with security and reliability implications. There is a browser argument you can use during setup, "--single-process", but as noted in Chromium docs this is not supported, and we don't recommend this:
https://www.chromium.org/developers/design-documents/process-models

Are there specific concerns or problems you are running into with the current process model?

@champnic
Copy link
Member

champnic commented Jun 1, 2023

Closing old issue. Please let me know if we need to re-open this for any reason. Thanks!

@champnic champnic closed this as not planned Won't fix, can't repro, duplicate, stale Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants