I am writing an API
using Asp.net Core 3.1
. I'm using IHostedService
for background processing in the API
.
IHostedService
class:
public class DataUpdateBackgroundService : Microsoft.Extensions.Hosting.BackgroundService
{
private ITurkeyProvinceDataService _dataService;
public DataUpdateBackgroundService(ITurkeyProvinceDataService dataService)
{
_dataService = dataService;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
stoppingToken.Register(() =>
Console.WriteLine(""));
while (!stoppingToken.IsCancellationRequested)
{
// Your code here
_dataService.UpdateData();
await Task.Delay(TimeSpan.FromMinutes(10), stoppingToken);
}
}
}
In my UpdateData
function,
I record data in a database for 10 minutes. I am pulling this saved data from a different API.
As such, it works smoothly on my local device.
When I publish this version in Azure Web Service
, I get the error in the title. But if I don't use my UpdateData
function, I don't get the error.
I could not understand whether it is related to Azure or my function should be in a structure like async. Can you help me with this?
var info = TimeZoneInfo.FindSystemTimeZoneById("Turkey Standard Time");
that i use for date operations in update data function – Muhammet Caylak