docs-maui
docs-maui copied to clipboard
.NET MAUI 9: Configure fire and forget for Android disposal on BlazorWebView
In .NET MAUI 9, if you encounter hangs on Android with BlazorWebView you can enable an AppContext switch in MauiProgram:
AppContext.SetSwitch("BlazorWebView.AndroidFireAndForgetAsync", isEnabled: true);
This switch enables BlazorWebView to fire and forget the async disposal that occurs. By default, BlazorWebView does async-over-sync for disposal, meaning that it blocks the thread until the async disposal is complete. However, this can cause deadlocks if the disposal needs to run code on the same thread (because that thread is blocked while waiting).
Enabling this new switch means that disposal can return before all objects are disposed, which can cause behavioral changes in an app. The items that are disposed are partially Blazor's own internal types, but also app-defined types such as scoped services used within the BlazorWebView portion of the app.
More info: https://github.com/dotnet/maui/pull/22496