Determine the time of execution of the next task based on the end of the current execution in Windows Service application C #

0

Here's my problem. I have an application as a windows service that needs to be executed 15 seconds after the current execution of the task is finished.

The task basically performs operations on the database, and it may take more than 15 seconds for the task to run.

My code to determine the execution interval looks like this:

worker = new Timer(new TimerCallback(saveFiles), null, 0, interval);
    
asked by anonymous 26.09.2017 / 22:39

1 answer

1

Just make the application wait for a while before running the operation again.

using System.Threading.Tasks;

// outras coisas

public static async void saveFiles()
{
    // Fazer um monte de coisa demorada

    await Task.Delay(15000);
    saveFiles();
}

Or

while(true)
{
    saveFiles();
    await Task.Delay(15000);
}
    
26.09.2017 / 23:14