seyounth.hyosung.ty/Seyounth.Hyosung/Services/ApplicationHostService.cs
2025-03-16 03:17:36 +08:00

40 lines
1.3 KiB
C#

using System.Windows;
using Microsoft.Extensions.Hosting;
using Seyounth.Hyosung.Views;
namespace Seyounth.Hyosung.Services;
public class ApplicationHostService(IServiceProvider serviceProvider) : IHostedService
{
/// <summary>
/// Triggered when the application host is ready to start the service.
/// </summary>
/// <param name="cancellationToken">Indicates that the start process has been aborted.</param>
public async Task StartAsync(CancellationToken cancellationToken)
{
await HandleActivationAsync();
}
/// <summary>
/// Triggered when the application host is performing a graceful shutdown.
/// </summary>
/// <param name="cancellationToken">Indicates that the shutdown process should no longer be graceful.</param>
public async Task StopAsync(CancellationToken cancellationToken)
{
await Task.CompletedTask;
}
/// <summary>
/// Creates main window during activation.
/// </summary>
private async Task HandleActivationAsync()
{
if (!Application.Current.Windows.OfType<MainWindow>().Any())
{
Application.Current.MainWindow = serviceProvider.GetService(typeof(MainWindow)) as MainWindow;
Application.Current.MainWindow.Show();
}
await Task.CompletedTask;
}
}