-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[release/9.0.1xx] [Blazor Hybrid] Fire and forget BlazorWebView
disposal by default
#25430
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
using Microsoft.Extensions.FileProviders; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Microsoft.Maui; | ||
using Microsoft.Maui.Dispatching; | ||
using Microsoft.Maui.Handlers; | ||
using WebView2Control = Microsoft.UI.Xaml.Controls.WebView2; | ||
|
@@ -30,13 +31,24 @@ protected override void DisconnectHandler(WebView2Control platformView) | |
{ | ||
if (_webviewManager != null) | ||
{ | ||
// Dispose this component's contents and block on completion so that user-written disposal logic and | ||
// Blazor disposal logic will complete. | ||
_webviewManager? | ||
// Start the disposal... | ||
var disposalTask = _webviewManager? | ||
.DisposeAsync() | ||
.AsTask() | ||
.GetAwaiter() | ||
.GetResult(); | ||
.AsTask()!; | ||
|
||
if (IsBlockingDisposalEnabled) | ||
{ | ||
// If the app is configured to block on dispose via an AppContext switch, | ||
// we'll synchronously wait for the disposal to complete. This can cause a deadlock. | ||
disposalTask | ||
.GetAwaiter() | ||
.GetResult(); | ||
} | ||
else | ||
{ | ||
// Otherwise, by default, we'll fire-and-forget the disposal task. | ||
disposalTask.FireAndForget(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unlike with the other There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this code is fine. |
||
} | ||
|
||
_webviewManager = null; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic ensures that if the
"BlazorWebView.AndroidFireAndForgetAsync"
switch was specified previously, we will continue to use that value, regardless of whether the newAppContext
switch is also specified.