Skip to content
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

Implement IAsyncDisposable on MauiApp #13424

Merged
merged 1 commit into from
Feb 22, 2023
Merged

Conversation

Eilon
Copy link
Member

@Eilon Eilon commented Feb 17, 2023

Fixes #13422

See the linked issue #13422 for more details. This change is required for some BlazorWebView test updates I want to make, because they register IAsyncDisposable services, and without this change if you call MauiApp.Dispose() (sync) you get an exception.

Note that this change has no effect on any typical MAUI app because no one disposes the MauiApp object at all (the process just ends). But in tests we create/destroy many apps, and that's where I hit this.

@Eilon Eilon added the area-core-hosting Extensions / Hosting / AppBuilder / Startup label Feb 17, 2023
@Eilon Eilon requested review from mattleibow and a team February 17, 2023 18:29
@Eilon Eilon merged commit c725092 into main Feb 22, 2023
@Eilon Eilon deleted the eilon/mauiapp-async-dispose branch February 22, 2023 19:09
@MartyIX
Copy link
Contributor

MartyIX commented Feb 22, 2023

because no one disposes the MauiApp object at all (the process just ends).

We do. We resorted to some ugly things to dispose it.

@Eilon
Copy link
Member Author

Eilon commented Feb 22, 2023

because no one disposes the MauiApp object at all (the process just ends).

We do. We resorted to some ugly things to dispose it.

Well it's just you and me then. The only humans on this planet to dispose a MauiApp! 😁 But in all seriousness, I'm curious your thoughts on this issue and the fix that was just merged. Does it help or hinder? Do you have remaining issues? Is it more about the challenge of how to even get MauiApp to be disposed as part of app shutdown?

@MartyIX
Copy link
Contributor

MartyIX commented May 17, 2023

@Eilon Sorry for responding so late but I have tried this feature with .NET8p4 and it seems to work great! So we can remove workarounds we added.

if (_services is IAsyncDisposable asyncDisposable)
{
// Fire and forget because this is called from a sync context
await asyncDisposable.DisposeAsync();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PureWeen should this be using the FireAndForget method to avoid breaking the app? Maybe we can't log but we should at least catch the exceptions?

@github-actions github-actions bot locked and limited conversation to collaborators Dec 13, 2023
@samhouts samhouts added the fixed-in-8.0.0-preview.2.7871 Look for this fix in 8.0.0-preview.2.7871! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-core-hosting Extensions / Hosting / AppBuilder / Startup fixed-in-8.0.0-preview.2.7871 Look for this fix in 8.0.0-preview.2.7871!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MauiApp.Dispose fails when an IAsyncDisposable service is registered
6 participants