how to dispose the BlazorWebView in WPF blazor hybrid application?
William Liu
466
Reputation points
I have a usercontrol which contains BlazorWebView control. After load/unload this usercontrol several times, I find there are more and more Microsoft Edge WebView2
appear in Windows task manager. I guess it was caused by the unreleased BlazorWebView resource. I also find the BlazorWebview is IAsyncDisposable, does it mean we should dispose it after using it? If so, please provide a demo to show how to dispose it.
I tried the following codes, it seems the code release the WebView2 resource sometime, but it will crush the WPF application if I load/unload the usercontrol too frequently.
public sealed partial class HomeView
{
public HomeView()
{
InitializeComponent();
Unloaded += HomeView_Unloaded;
}
private async void HomeView_Unloaded(object sender, System.Windows.RoutedEventArgs e)
{
await BlazorWebView.DisposeAsync();
}
}
Sign in to answer