Comments (4)
@robloo I thought it's a regression from #15438, but I am not sure anymore.
First of all, this specific code you provided has two issues:
- It's not allowed to call TryShutdown during shutdown, app will throw "Application is already shutting down" (old behavior). In your code there is no delay in DeleteWorkingFileAndExit. But I assume your real app an actual dialog.
- If I simulate some delay in DeleteWorkingFileAndExit, it still works as expected (kinda?). TryShutdown is called, OnClosing is executed again, cancelled again (you always set e.Cancel = true), and TryShutdown is called again after delay - trapping app in the loop.
This loop from #2 is what was changed between versions.
In 11.1-beta1 and before we had an issue that TryShutdown
was closing the app even if Window.Closing was cancelled. It still was trapping in the loop of cancellation, but Dispatcher.UIThread.InvokeShutdown
eventually was killing the app.
In 11.1-beta2 it was fixed, and TryShutdown
now actually respects e.Cancel from Window.Closing.
from avalonia.
I am going to remove "regression" label, as it's not an actual regression, but app relied on the previously broken behavior.
If you need to force app to be closed (ignoring Window.Closing event), you need to use Lifetime.Shutdown
method (without Try). The difference is that Shutdown
method actually forces app to be closed, exactly what is needed in your use case, I assume. It forces closing by not calling ShutdownRequested and Window.Closing events that can be cancelled.
But I will keep this issue opened, as:
- Difference between Shutdown/TryShutdown is not always clear.
- Ideally there should be an error or warning, when app is stack in "closing cancellation loop".
Issue title should be adjusted too.
from avalonia.
Or we can create another issue instead, and close this one.
from avalonia.
It's not allowed to call TryShutdown during shutdown, app will throw "Application is already shutting down" (old behavior). In your code there is no delay in DeleteWorkingFileAndExit. But I assume your real app an actual dialog.
Yes, there are dialogs in the full code. Note that I would have expected intercepting Window close to be separate than application shutdown so TryShutdown() is not actually called within TryShutdown().
In other words, when a Window is closing itself I would expect this to occur BEFORE the application shutdown process. Only once all windows are closed would Avalonia then trigger application shutdown. What this means is if you stop a window from closing TryShutdown() is never actually called because the application shutdown process never started. This makes more sense to me and I suspect is how WPF/UWP work in this area (this code was ported from UWP/WinUI where it worked there).
If I simulate some delay in DeleteWorkingFileAndExit, it still works as expected (kinda?). TryShutdown is called, OnClosing is executed again, cancelled again (you always set e.Cancel = true), and TryShutdown is called again after delay - trapping app in the loop.
Again, I am handling window close which I would expect to occur before any actual shutdown.
So I have a few high-level thoughts here: The distinction in Avalonia between Application, TopLevel and Window is almost certainly confusing/wrong in several cases.
- For example, services are "global" and I would expect them to be available from the Application class rather than TopLevel.. another topic
- Application closing should be fully handled in the Application class itself rather than Window
- Cancelling window close should not trigger application shutdown
- The top caption buttons need to route to the window and be processed there FIRST. This ensures pressing X starts window close rather than application shutdown.
Difference between Shutdown/TryShutdown is not always clear.
Yea, I wasn't aware we had two different methods for this and in my code just using Shutdown
should solve the actual issue.
I would leave this open for now as we discuss the above. We should also document a behavioral breaking change for 11.1 in this area.
from avalonia.
Related Issues (20)
- when set `{x:Null}` to any control's `FontFamily` property, application will crashed HOT 4
- BackgroundSizing Inner/Outer do not work like Center when CornerRadius is very large (i.e. 999) HOT 5
- DataContext value in DevTools displayed as null if type of value inherited from System.ComponentModel.Component HOT 3
- InlineUIContainer breaks SelectableTextBlock selection
- DBus folder dialog doesn't work with RHEL 8.5 HOT 1
- SaveFilePickerAsync duplicates FilePickerFileType extension when there is more than one period in the extension.
- When mounted, TabStrip changes SelectedItem to the first one and then reverts it back
- iOS apps don't build HOT 1
- CPU usage is really high again... HOT 5
- DataGrid Adaptive exception HOT 6
- AutoCompleteBox not biding SelectedItem when using AsyncPopulator HOT 1
- Screen API refactoring HOT 5
- Android - Crash on bluetooth keyboard device connection and disconnection HOT 2
- [Linux] WindowStartupLocation does not respect DesktopScaling factor HOT 2
- [11.1-beta2] Regression: Window System buttons is not visible when `ExtendClientAreaToDecorationsHint="True"` HOT 2
- AccessViolationException when using RenderDoc on Windows HOT 1
- Copying of file not working as expected
- TabControl item headers go invisible after screen change
- Windows OpenGL FullScreen artifacts with popups and wrong mouse hittests HOT 3
- Double autocompletebox dropdown HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from avalonia.