2022-10-14 16:08:54 +08:00
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
using Microsoft.Extensions.Logging;
|
2023-06-06 16:43:46 +08:00
|
|
|
using Serilog;
|
2022-10-14 16:08:54 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2023-06-06 16:43:46 +08:00
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
2022-10-14 16:08:54 +08:00
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
namespace BackendWorkerService
|
|
|
|
{
|
|
|
|
public class Worker : BackgroundService
|
|
|
|
{
|
|
|
|
private readonly ILogger<Worker> _logger;
|
|
|
|
|
|
|
|
public Worker(ILogger<Worker> logger)
|
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
|
|
|
{
|
|
|
|
while (!stoppingToken.IsCancellationRequested)
|
|
|
|
{
|
|
|
|
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
|
|
|
await Task.Delay(1000, stoppingToken);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|