40 lines
1.3 KiB
C#
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;
|
|
}
|
|
} |