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

Asked

Viewed 68 times

0

This is my problem. I have an application as a windows service that needs to run 15 seconds after the current job execution is finished.

The task basically performs database operations and may be that the execution takes longer than 15 seconds, hence the problem.

My code to determine the execution interval is like this:

worker = new Timer(new TimerCallback(saveFiles), null, 0, interval);

1 answer

1


Just make the application wait a little 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);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.