Hakan Axheim

Hakan Axheim

  • NA
  • 201
  • 32.5k

Regarding: Windows Service programming

Feb 16 2021 8:47 AM
Hi,
 
I am trying to build a Windows Service in C#.
 
I have created the project in Visual Studio 2019 with template Worker Service. 
As default it will be created a method:in the Worker.cs class

protected override async Task ExecuteAsync(CancellationToken stoppingToken) 
 
In that method there is a  while loop where I want to call a method in which I shall select values from a database.
In this while loop I have a Task.Delay for some seconds, and this delay is configurable in the appsettings.json.
 
But I want this program to wait for the selection from the database is finished, i.e. if I have set the delay to 2 seconds and the database selection will take 3 seconds. Then I wan't a larger delay. 
 
How can I do that?

Answers (1)