-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathWorker.cs
More file actions
31 lines (26 loc) · 850 Bytes
/
Worker.cs
File metadata and controls
31 lines (26 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
namespace StructureMap.AspNetCoreV2.Sample
{
class Worker : BackgroundService
{
private readonly ILogger _logger;
public Worker(ILogger logger)
{
_logger = logger;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_logger.Info("Worker is starting.");
stoppingToken.Register(() => _logger.Info("Worker is stopping."));
while (!stoppingToken.IsCancellationRequested)
{
_logger.Info("Worker running at: {0}", DateTime.UtcNow);
await Task.Delay(1000, stoppingToken);
}
_logger.Info("Worker background task is stopping.");
}
}
}