Created
February 19, 2021 18:39
-
-
Save ankitvijay/c9b375e07d936fcf5baa28fb6f28100e to your computer and use it in GitHub Desktop.
Default Background Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using Microsoft.Extensions.Hosting; | |
using Microsoft.Extensions.Logging; | |
namespace SchedulerJobSample.Worker | |
{ | |
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); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment