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

Start app without windows? #857

Closed
MonkAlex opened this issue Jan 16, 2017 · 12 comments
Closed

Start app without windows? #857

MonkAlex opened this issue Jan 16, 2017 · 12 comments

Comments

@MonkAlex
Copy link
Contributor

MonkAlex commented Jan 16, 2017

I want create ask dialog and then do any action. Show\ShowDialog methods only asynchronic, no idea, how to do it and dont close app. Where "ShutdownMode" analog with "OnExplicitShutdown" value from WPF?

    static void Main(string[] args)
    {
      InitializeLogging();
      AppBuilder.Configure<App>()
          .UsePlatformDetect()
          .SetupWithoutStarting();

      var dialog = new SimpleDialog();
      // Cannot await, Main not async
      var dialogResult = await dialog.ShowDialog();
      ...
    }
@wieslawsoltes
Copy link
Collaborator

@MonkAlex Try this:

static void Main(string[] args)
{
    var app = new Application();
    AppBuilder.Configure(app)
        .UsePlatformDetect()
        .SetupWithoutStarting();

    var dialog = new SimpleDialog();
    dialog.Show();
    app.Run(dialog);
}

@MonkAlex
Copy link
Contributor Author

@wieslawsoltes its work, but i want dialog with custom buttons, need return it from ShowDialog method.

@MonkAlex
Copy link
Contributor Author

MonkAlex commented Jan 16, 2017

Work this realization, but normal this or not, no idea:

    public virtual IButton Show()
    {
      CancellationTokenSource source = new CancellationTokenSource();
      
      var dialog = new Window(this);
      dialog.Closed += (sender, args) => source.Cancel();
      dialog.Show();

      Dispatcher.UIThread.MainLoop(source.Token);
      return dialog.ResultButton;
    }

MainLoop code hard for me, don't know, can i use it or not.

@Gillibald
Copy link
Contributor

I will introduce ShutdowmMode soon. That is next in my list.

@jkoritzinsky
Copy link
Collaborator

Has this been fixed by #1662?

@Gillibald
Copy link
Contributor

Gillibald commented Sep 12, 2018

ShutdownMode (ExitMode) is fully implemented so it should be fixed.

@MonkAlex
Copy link
Contributor Author

I do on start

      BuildAvaloniaApp().SetExitMode(ExitMode.OnExplicitExit).SetupWithoutStarting();

Then try to create and show window (remove Dispatcher.UIThread.MainLoop(source.Token); after show):

      using (DialogTokenSource = new CancellationTokenSource())
      {
        var dialog = new DialogWindow(this);
        dialog.Closed += (sender, args) => CloseImpl();
        DialogTokenSource.Token.Register(() => Dispatcher.UIThread.InvokeAsync(() => dialog.Close()));
        dialog.Show();

        return dialog.ResultButton;
      }

And app closed.

How to do it? _

@Gillibald
Copy link
Contributor

Gillibald commented Jan 20, 2019

I need to see more of your starting sequence to be sure what is going on. In general you need the main loop to run anything. So altering that isn't a good idea. You can run the application without an main window.

@MonkAlex
Copy link
Contributor Author

https://github.com/MonkAlex/CommonLibraries/tree/exitmode
Simple app, try to use exit mode in last commit.

@Gillibald
Copy link
Contributor

Try to call https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Controls/Application.cs#L272 before you create any visual. Just create your own token source and pass in a token. You can the request a cancelation on your token source or call Exit on your Application.

We should allow passing null to Run(Window mainWindow) instead of this.

@MonkAlex
Copy link
Contributor Author

In WPF i can just run app and do nothing. I think, OnExplicitExit must enable this behavior.

And, i can run MainLoop without ExitMode configuration, what it changed?

@Gillibald
Copy link
Contributor

You don't run the Application anywhere. That wouldn't work with WPF either.

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

No branches or pull requests

4 participants