Winforms process not stopping correctly when using WebView2
See original GitHub issue.NET version
6.0.5
Did it work in .NET Framework?
Not relevant to WebView2.
Did it work in any of the earlier releases of .NET Core or .NET 5+?
No response
Issue description
I have created a Winforms app using Blazor through WebView2. This works great until I try to close the app.
While running, all of the processes are contained under the parent under the Apps section of task manager:
After closing the app with the close button, I see this in the task manager under the background process section: The webview processes also remain in the background:
If I manually kill the app process at this stage, the WebView processes also stop.
My current fix is the following:
private void Form1_FormClosing(object? sender, FormClosingEventArgs e)
{
Environment.Exit(0); //calling Exit kills the background process associated with WebView2
}
This kills the background process, which in turn kills the WebView2 processes.
Steps to reproduce
Create a new Winforms app and create a blazor webview2 app as per: https://docs.microsoft.com/en-us/aspnet/core/blazor/hybrid/tutorials/windows-forms?view=aspnetcore-6.0
Publish the app and run it, ideally without Visual Studio running to make sure nothing else is running WebView2. Close the app, and check to see if the WebView2 processes are still running.
I have observed this issue on a testing server with the published build, not when running in debug mode from Visual Studio.
Issue Analytics
- State:
- Created a year ago
- Comments:24 (11 by maintainers)
Top GitHub Comments
Moved to MAUI repo so we can investigate as a potential Blazor Hybrid issue.
@MackinnonBuck gosh my memory on this is super blurry. Perhaps we can discuss at the next engineering sync?