From 3da2292c6b9b30906412dc81fd7e366b5d6fa0a4 Mon Sep 17 00:00:00 2001 From: Easley wang Date: Tue, 9 Jul 2024 07:49:32 +0800 Subject: [PATCH] Add an overload for ClassicDesktopStyleApplicationLifetime (#16167) * add an overload with no parameters for ClassicDesktopStyleApplicationLifetime * add an overload with no parameters for ClassicDesktopStyleApplicationLifetime * add a new internal func: Startcore(args) --------- Co-authored-by: Max Katz --- .../ClassicDesktopStyleApplicationLifetime.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs b/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs index 43c140a05f..2957214308 100644 --- a/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs +++ b/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs @@ -117,16 +117,30 @@ namespace Avalonia.Controls.ApplicationLifetimes } public int Start(string[] args) + { + return StartCore(args); + } + + /// + /// Since the lifetime must be set up/prepared with 'args' before executing Start(), an overload with no parameters seems more suitable for integrating with some lifetime manager providers, such as MS HostApplicationBuilder. + /// + /// exit code + public int Start() + { + return StartCore(Args ?? Array.Empty()); + } + + internal int StartCore(string[] args) { SetupCore(args); - + _cts = new CancellationTokenSource(); // Note due to a bug in the JIT we wrap this in a method, otherwise MainWindow // gets stuffed into a local var and can not be GCed until after the program stops. // this method never exits until program end. - ShowMainWindow(); - + ShowMainWindow(); + Dispatcher.UIThread.MainLoop(_cts.Token); Environment.ExitCode = _exitCode; return _exitCode;