simplify OnStartup method

This commit is contained in:
ema
2023-11-26 02:13:30 +08:00
parent ecfaba7252
commit e06e7c878c
2 changed files with 8 additions and 17 deletions

View File

@@ -1,9 +1,7 @@
<Application x:Class="BetterGenshinImpact.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Exit="OnExit"
Startup="OnStartup">
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>

View File

@@ -112,16 +112,14 @@ public partial class App : Application
/// <summary>
/// Occurs when the application is loading.
/// </summary>
private void OnStartup(object sender, StartupEventArgs e)
protected override async void OnStartup(StartupEventArgs e)
{
StartUp();
}
base.OnStartup(e);
private async void StartUp()
{
try
{
await StartUpCoreAsync();
RegisterEvents();
await _host.StartAsync();
await UrlProtocolHelper.RegisterAsync();
}
catch (Exception ex)
@@ -136,19 +134,14 @@ public partial class App : Application
}
}
private async Task StartUpCoreAsync()
{
RegisterEvents();
await _host.StartAsync();
}
/// <summary>
/// Occurs when the application is closing.
/// </summary>
private async void OnExit(object sender, ExitEventArgs e)
protected override async void OnExit(ExitEventArgs e)
{
await _host.StopAsync();
base.OnExit(e);
await _host.StopAsync();
_host.Dispose();
}