mirror of
https://github.com/techgarage-ir/MTWireGuard.git
synced 2025-08-30 06:39:27 +02:00
Multiarch new method
This commit is contained in:
parent
768d5084f2
commit
0c015d6024
5 changed files with 68 additions and 4 deletions
40
Application/ApplicationLifetimeService.cs
Normal file
40
Application/ApplicationLifetimeService.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
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()
|
||||
{
|
||||
// ...
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue