-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Application ExitMode #1662
Application ExitMode #1662
Conversation
Thanks for this @Gillibald. This is the same as #1617 right? Next time could you squash your commits and force push instead of creating a new PR? It's best to keep the conversation in one PR. Will review this shortly. |
Yes it is the same. Just didn't know how to remove the merge commits. This will not happen again in the future. Now i know how to sync my fork properly. |
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.
Hmm, now if i set this in ControlCatalog.Desktop:
BuildAvaloniaApp().SetExitMode(ExitMode.OnMainWindowClose).Start<MainWindow>();
The application doesn't appear to start.
Edit: Hmm ignore that, it seems to be working now, not sure what was happening...
src/Avalonia.Controls/Application.cs
Outdated
|
||
_mainLoopCancellationTokenSource = new CancellationTokenSource(); | ||
|
||
Dispatcher.UIThread.InvokeAsync( |
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.
Why does this need to be done via an invoke?
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.
I haven't found a better solution to show the main window and start up the main loop. The invoke queues the action for execution and gets executed when the main loop runs.
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.
I've tried changing this to:
mainWindow.Show();
MainWindow = mainWindow;
Dispatcher.UIThread.MainLoop(_mainLoopCancellationTokenSource.Token);
And it seems to work. What am I missing?
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.
If everything works its fine. Not sure about side effects. My solution only runs after the main loop is running. Maybe show does the same. At some point something has to be invoked on the main thread. Is it possible to call run on a different thread or even Window.Show? My solution would avoid that issue.
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.
Just tried what you did and it didn't work. My approach always runs. Don't know why yours work on your environment.
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.
Have you tried it with Skia or Direct2D1? Yours works with Skia but not with Direct2D1 on my machine.
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.
I tried it with Win32/D2D but it also works with skia here. Strange that it doesn't work with D2D on your machine, I don't see how the rendering backend would affect whether a window gets shown or not - that should depend on the windowing backend.
It's also strange because this is how it works on master
- Window.Show
is called from AppBuilderBase.Start
before the main loop is started.
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.
Dont understand it either has probably something to do with the. net runtime. With .Net Core I dont need invoke. Will remove the invoke call and just hope others don't have the problem.
src/Avalonia.Controls/ExitMode.cs
Outdated
|
||
namespace Avalonia | ||
{ | ||
public enum ExitMode |
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.
Could you add some XML documentation to this enum?
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.
Will add some comments
…ibald/Avalonia into feature/ApplicationExitMode
Thanks @Gillibald ! |
This PR introduces a way to control when the application exits. You can either let the application exit explicitly or implicitly. Furthermore you can now access the main window and open Windows under the current application instance.
The current state calls exit when the main window was closed and there is no way to control this behavior
You are able to control when the application exits.
In the past all open windows where stored under Window and moved to Application with these changes. A ExitMode property was added to application and a SetExitMode method was added to the AppBuilder.
Checklist:
See #1565