Skip to content

Commit

Permalink
add an overload with no parameters for ClassicDesktopStyleApplication…
Browse files Browse the repository at this point in the history
…Lifetime
  • Loading branch information
NeverMorewd committed Jul 1, 2024
1 parent a85c20b commit 3ec0813
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,26 @@ public int Start(string[] args)
return _exitCode;
}

/// <summary>
/// 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.
/// </summary>
/// <returns></returns>
public int Start()
{
SetupCore(Args ?? Array.Empty<string>());

_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();

Dispatcher.UIThread.MainLoop(_cts.Token);
Environment.ExitCode = _exitCode;
return _exitCode;
}

[MethodImpl(MethodImplOptions.NoInlining)]
private void ShowMainWindow()
{
Expand Down

0 comments on commit 3ec0813

Please sign in to comment.