@@ -19,7 +19,7 @@ process is active, and moving to a new WebView2 Runtime version after a
1919` NewBrowserVersionAvailable ` event.
2020
2121This event is raised for both expected and unexpected termination of the
22- collection of processes, after all resources, including the user data folder,
22+ collection of processes, after all resources, including the user data folder,
2323used by the WebView2 Runtime have been released. The
2424` CoreWebView2BrowserProcessExitedEventArgs ` lets app developers get
2525the ` BrowserProcessExitKind ` so they can decide how to handle different exit
@@ -86,7 +86,8 @@ void AppWindow::CloseWebView(/* ... */) {
8686 // the browser has exited but before our handler gets to run, a new
8787 // browser process will be created and lock the user data folder
8888 // again. Do not attempt to cleanup the user data folder in these
89- // cases. We check the PID of the exited browser process against the
89+ // cases. If this happens, the PID of the new browser process will be
90+ // different to the PID of the older process, we check against the
9091 // PID of the browser process to which our last CoreWebView2 attached.
9192 if (pid == m_newestBrowserPid)
9293 {
@@ -102,15 +103,21 @@ void AppWindow::CloseWebView(/* ... */) {
102103 m_webViewEnvironment = nullptr;
103104 CleanupUserDataFolder();
104105 }
105- } else {
106- MessageBox(m_mainWindow, L"A new browser process prevented cleanup of "
107- L"the user data folder.", L"Cleanup User Data Folder", MB_OK);
106+ }
107+ else
108+ {
109+ // The exiting process is not the last in use. Do not attempt cleanup
110+ // as we might still have a webview open over the user data folder.
111+ MessageBox(
112+ m_mainWindow,
113+ L"A new browser process prevented cleanup of the user data folder.",
114+ L"Cleanup User Data Folder", MB_OK);
108115 }
109116
110117 return S_OK;
111118 }).Get(),
112119 &m_browserExitedEventToken));
113-
120+
114121 // ...
115122
116123 // Close the WebView from its controller.
@@ -143,7 +150,7 @@ void AppWindow::CloseWebView(/* ... */) {
143150 <!-- ... -->
144151
145152 <DockPanel DockPanel.Dock="Top">
146-
153+
147154 <!-- ... -->
148155
149156 <TextBox x:Name="url" Text="{Binding ElementName=webView,Path=Source,Mode=OneWay}">
@@ -394,7 +401,7 @@ namespace Microsoft.Web.WebView2.Core
394401 /// process recovers from a crash by recreating its WebView controls.
395402 ///
396403 /// Note this is an event from `CoreWebView2Environment`, not `CoreWebView2`. The
397- /// difference between this `BrowserProcessExited` event and the `CoreWebView2`'s
404+ /// difference between this `BrowserProcessExited` event and the `CoreWebView2`'s
398405 /// `ProcessFailed` event is that `BrowserProcessExited` is raised for any (expected
399406 /// and unexpected) **browser process** (along its associated processes) exits, while
400407 /// `ProcessFailed` is raised only for **unexpected** browser process exits, or for
0 commit comments