Created
August 29, 2024 05:22
-
-
Save VergilGao/9d520af96214e7c5742304bc9253afaf to your computer and use it in GitHub Desktop.
WPF 通用主机
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private IHost host = null!; | |
public static IServiceProvider ServiceProvider { get; private set; } = null!; | |
protected override async void OnStartup(StartupEventArgs e) | |
{ | |
host = CreateHostBuilder(e.Args).Build(); | |
ServiceProvider = host.Services; | |
await host.StartAsync(); | |
MainWindow = host.Services.GetRequiredService<MainWindow>(); | |
MainWindow.Show(); | |
base.OnStartup(e); | |
} | |
protected override async void OnExit(ExitEventArgs e) | |
{ | |
await host.StopAsync(); | |
host.Dispose(); | |
base.OnExit(e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment