C# Close WebView2 problem
Recently I changed my WebBrowser to WebView2. The WebView2 remains hanging on the desktop on the top-Left corner when closing its container Form.
After exiting the application all the WebView2 instances remain running in the background - they will be hidden but you can still see them in the task manager. Calling the container forms several times will kill the performance and will generate many errors.
To reproduce the problem, all you need to do is to call and close a Form containing a WebView2 several times.
When you close the Form, you will see that the WebView2 is still hanging on the desktop and waiting to be closed manually. There is no way to close it except if you log off from windows or using the TaskManager. Using the task manager you have to kill all the created processes of Microsoft Edge one by one.
Here is the code I am using. I have a simple application with a list of PDF bills. The application will display any selected bill in a PDFViewer Form. The PDFViewer receives the PDF full pathname and it displays it using WebView2. The PDF Viewer works fine but the problem occurs after you close it.
1) The following Form will be displayed to call the PdfViewer

2) When you click on PDF Preview button, the following code will be called:
BillPdfViewerForm billPdfViewerForm = new BillPdfViewerForm(this, m_billItem.BillId, strPdfFullPathName);
if (billPdfViewerForm.ShowDialog() == DialogResult.OK)
{
Close();
}
The BillPdfViewerForm is a simple form with a WebView2 that will display the PDF received in strPdfFullPathName. That's all. This is how the PDFViewer will look like after this call:
Notice that there nothing displayed behind my application you can still see the desktop after the PDFViewer is displayed. But when you close this form, You will see the WebView2 hanging on the desktop at the top left corner

I can still use my application but each time I close a pdfViewer I get a new WebView2 instance running in the background. Even after closing my application, all created WebView2 Instance will remain running in the background. I can see many Microsoft Edge still running in the the task manager:
