Skip to content

Commit

Permalink
timer calibration fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wiegell committed Dec 6, 2022
1 parent d26b558 commit b492739
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions AstroWall/BusinessLayer/Wallpaper/Wallpaper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,19 @@ public async void createNoonCheck()
TaskCancelWrap newTCW = new TaskCancelWrap();
newTCW.task = Task.Run(async () =>
{
log("Noontask started (before delay)");
DateTime now = DateTime.Now;
DateTime nowPlusOneDay = DateTime.Now.AddDays(1);
DateTime tomorrowNoon = new DateTime(nowPlusOneDay.Year, nowPlusOneDay.Month, nowPlusOneDay.Day, 12, 0, 0);
DateTime noonToday = new DateTime(now.Year, now.Month, now.Day, 12, 0, 0);

bool shouldSetCheckTomorrow = now > noonToday;
log("Setting next noon check to " + (shouldSetCheckTomorrow ? "tomorrow" : "today"));

DateTime dayToSetCheck = now.AddDays(shouldSetCheckTomorrow ? 1 : 0);
DateTime nextNoon = new DateTime(dayToSetCheck.Year, dayToSetCheck.Month, dayToSetCheck.Day, 12, 0, 0);
// Debugging line
// DateTime tomorrowNoon = now.AddMilliseconds(120000);
applicationHandler.Prefs.NextScheduledCheck = tomorrowNoon;
int diffMSuntilTomorrowNoon = (int)tomorrowNoon.Subtract(now).TotalMilliseconds;
log("MS diff until tomorrow noon: " + diffMSuntilTomorrowNoon);
applicationHandler.Prefs.NextScheduledCheck = nextNoon;
int diffMSuntilTomorrowNoon = (int)nextNoon.Subtract(now).TotalMilliseconds;
log("MS diff until next noon: " + diffMSuntilTomorrowNoon);
await Task.Delay(diffMSuntilTomorrowNoon);
log("Noon task token status: " + newTCW.token.IsCancellationRequested);
if (!newTCW.token.IsCancellationRequested) noonCallback();
Expand Down

0 comments on commit b492739

Please sign in to comment.