Open draganapopova opened 3 years ago
@draganapopova Hey Dragana,
I believe when a WPF window is closed it will call Dispose/Close on the WebView2 control, which will clean it up and not call onbeforeunload
(which is how D365 is doing the close logic I assume?). Unfortunately we don't have a different way to shutdown that will call 'onbeforeunload', except through Reload() or by navigating as you mention. Is there a reason you don't want to wait for reload() or are unable to use it on the FormClosing event?
@champnic
Thanks for the reply :) The reason why I don't want to wait for the reload is because it consumes time and is not nice for the user to wait for reloading and I cannot use it on closing event since when the closing event in WPF is triggered it's already too late because it will not wait for the reload and the close event in D365 is not triggered. Btw when the url is loaded directly from Edge (not from WPF WebView2) and when I close the browser I don't experience the issue, so how is implemented there?
Even if we had a different way to shutdown, you'd have a similar timing issue as the website would need to be closed and run script, which can take some time. For the new navigation - calling .Reload()
will fire NavigationStarting
event and you can cancel the new navigation and use that event as the signal that closing is safe.
Re: WPF/D365 closing - Wouldn't it be too late if we provided an TryShutdownAsync function as well?
Hi,
I'm using WebView2 control (latest stable release 1.0.902.49, Microsoft Edge WebView2 Runtime 92.0.902.78) in WPF app.
Within the WebView2 control I'm launching D365 forms. The issue happens when the WPF window is closed and the close method logic from Dynamics 365 form should be executed, but it's not because it's not triggered. Is there any way to trigger WebView2 closing manually from code behind when WPF window is closing?
ps the WebView2.Reload() method triggers the close method in D365, but I'm not willing to wait for the reload and also I cannot use it on the WPF window closing event.
Thanks!
Br, Dragana
AB#25547807