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

Application ExitMode #1662

Merged
merged 12 commits into from
Jun 29, 2018
Merged

Conversation

Gillibald
Copy link
Contributor

  • What does the pull request do?
    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.
  • What is the current behavior?
    The current state calls exit when the main window was closed and there is no way to control this behavior
  • What is the updated/expected behavior with this PR?
    You are able to control when the application exits.
  • How was the solution implemented (if it's not obvious)?
    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

@grokys
Copy link
Member

grokys commented Jun 14, 2018

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.

@grokys grokys self-assigned this Jun 14, 2018
@Gillibald
Copy link
Contributor Author

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.

Copy link
Member

@grokys grokys left a 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...


_mainLoopCancellationTokenSource = new CancellationTokenSource();

Dispatcher.UIThread.InvokeAsync(
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

@grokys grokys Jun 18, 2018

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.


namespace Avalonia
{
public enum ExitMode
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will add some comments

@grokys grokys merged commit 4565aa8 into AvaloniaUI:master Jun 29, 2018
@grokys
Copy link
Member

grokys commented Jun 29, 2018

Thanks @Gillibald !

@Gillibald Gillibald deleted the feature/ApplicationExitMode branch July 30, 2018 09:53
@grokys grokys added this to the 0.7.0 milestone Apr 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants