-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[API Proposal]: Dispose Application in Generated Entry Point #10074
Comments
@koenigst I do not think it should dispose. Because we dispose the application before we exit. |
@koenigst What I mean is that the process has exited and the resource does not need to be released. |
@lindexi true, that is sufficient for resources cleaned up the os. I had issues with |
You've got multiple events raised to do your cleanups (e.g. flushing buffers) in and just making it Pick your poison, based on the expected lifetime:
Your original question doesn't raise the concern, but it's good to consult |
These events do allow for various ways to do cleanup. Another possibility would be just to write a custom entry point where the application is disposed. I do think that having a simple solution out of the box would be advantageous for developers who do not have the same depth of understanding. The analyzers will suggest implementing I also think it is a low effort and low risk change. |
Plus,
Your argument for abstracting those things away I understand, especially if you're coming from ASP.NET, after all, that's kinda Framework's job; but polluting the API surface with implementing Chances are if you need to clean up something on app exit, you need to initialize those things at startup as well, otherwise the lifetime is not very well defined and that is another issue. |
Background and motivation
If any disposable fields are present in the application (i.e.
App.xaml.cs
) the default analyzers will suggests implementingIDisposable
on the application class. The code generator for the entry point creates the application without disposing it at the end. This might confuse developers.The fix would be quite simple by just generating a using statement if the application class implements
IDisposable
.A workaround is possible by creating a custom entry point.
API Proposal
Generated output:
API Usage
Alternative Designs
No response
Risks
Application classes already implementing
IDisposable
will get an additional call toDispose
. This should be a small issue asDispose
should be safe to call multiple times.The text was updated successfully, but these errors were encountered: