Skip to content
This repository has been archived by the owner on Jan 30, 2019. It is now read-only.

Commit

Permalink
fix issue with reload at midnight (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicogbg authored and zhuridartem committed Feb 17, 2017
1 parent 8d0bd21 commit 7768223
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions DigitalSign/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ static class GlobalTimerWrapper
static private Page currentPage;
static readonly TimeSpan heartbeatDuration = new TimeSpan(0, 30, 0);
static readonly TimeSpan reloadContentIntervalDuration = new TimeSpan(0, 1, 0);
static bool reloadContentDone = false;

static public void StartReloadContentTimer(Page page)
{
currentPage = page;
if (reloadContentTimer == null)
{
reloadContentDone = false;
reloadContentTimer = new DispatcherTimer();
reloadContentTimer.Interval = reloadContentIntervalDuration;
reloadContentTimer.Tick += reloadContentTimer_Tick; // ensure this is only added once
Expand All @@ -66,11 +68,22 @@ static public void StartReloadContentTimer(Page page)
static void reloadContentTimer_Tick(object sender, object e)
{
DateTime time = DateTime.Now;
if (time.Hour == 0 && time.Minute == 0) // we want the content reload happens only at 0:00 every day, exact mid-night
// since DispatcherTimer aren't guarantee to fire immediately after interval expires and also because
// it started some when seconds within a minute there is no guarantee that time will exactly be 0:00
if (time.Hour == 0 && time.Minute >= 0 && time.Minute < 2)
{
// go to main page and reload slideshow page would trigger a content reload
currentPage.Frame.Navigate(typeof(MainPage));
currentPage.Frame.Navigate(typeof(SlideshowPage));
if (!reloadContentDone)
{
reloadContentDone = true;

// go to main page and reload slideshow page would trigger a content reload
currentPage.Frame.Navigate(typeof(MainPage));
currentPage.Frame.Navigate(typeof(SlideshowPage));
}
}
else
{
reloadContentDone = false;
}
}
}
Expand Down

0 comments on commit 7768223

Please sign in to comment.