question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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: image

After closing the app with the close button, I see this in the task manager under the background process section: image The webview processes also remain in the background: image

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:closed
  • Created a year ago
  • Comments:24 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
Eiloncommented, Jun 13, 2022

Moved to MAUI repo so we can investigate as a potential Blazor Hybrid issue.

1reaction
Eiloncommented, Sep 26, 2022

@MackinnonBuck gosh my memory on this is super blurry. Perhaps we can discuss at the next engineering sync?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Known Issues in WebView control - Windows
This guide highlights known limitations with the current release of the WebView control for Windows Forms and WPF applications.
Read more >
WebView2 Class
Some of the WebView2 and CoreWebView2 APIs may throw errors if invoked within these handlers due to being unable to communicate with the...
Read more >
WinForms Microsoft.Web.WebView2 Navigate, Page Fully ...
I am trying execute a method after the action this.webViewBrowser.CoreWebView2.Navigate(url). As of yet are failing as the page is not fully ...
Read more >
Process does not close after closing the form
I can believe the solution here is : Do not handle it. If the process is still pending that means you are not...
Read more >
Fighting WebView2 Visibility on Initialization - Rick Strahl
Problem: The virtual domain doesn't initialize until the WebView has initialized, which doesn't happen until the control becomes visible. End ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found