mirror of
https://github.com/techgarage-ir/MTWireGuard.git
synced 2025-08-19 08:58:17 +02:00
40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MTWireGuard.Application
|
|
{
|
|
public class ApplicationLifetimeService(IHostApplicationLifetime hostApplicationLifetime, ILogger logger) : IHostedService
|
|
{
|
|
public Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
hostApplicationLifetime.ApplicationStarted.Register(OnStarted);
|
|
hostApplicationLifetime.ApplicationStopping.Register(OnStopping);
|
|
hostApplicationLifetime.ApplicationStopped.Register(OnStopped);
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
|
=> Task.CompletedTask;
|
|
|
|
private void OnStarted()
|
|
{
|
|
logger.LogInformation("Registered: {Name}!", Environment.UserName);
|
|
}
|
|
|
|
private void OnStopping()
|
|
{
|
|
logger.LogWarning("Exiting: {MachineName}!", Environment.MachineName);
|
|
}
|
|
|
|
private void OnStopped()
|
|
{
|
|
// ...
|
|
}
|
|
}
|
|
}
|