I'm working on a project which needs to do something every 24h. I have a timer for that, but when i start the program i want it to delay the timer once så im sure it runs during the night.
The timer :
timeForFitbitUpdate = 86400000; // Setting 24 hours of intervals
Timer aTimer = new Timer(10);
aTimer.Elapsed += new ElapsedEventHandler(RunEvent);
aTimer.Interval = timeForFitbitUpdate;
aTimer.Enabled = true;
I have tried this code:
int delayTime = CalculateDelay();
var connectionString = ConfigurationManager.ConnectionStrings["VRT"].ConnectionString;
FitbitDataSave dataSave = new FitbitDataSave(connectionString);
await Task.Delay(delayTime);
dataSave.DoTimedWork();
but with other hardcoded miliseconds both in timer and the delay.. The delay was set to 5 minutes and timer to 5 minutes and it took the first time 10 minutes and after that 11 minutes and so on..
If any one have any ideas pls share thnx :)