Tuesday, November 26, 2013

Image refreshing not working in Windows 8 apps

I want to display a banner via a URL. The URL is static but the image content can be changed so it's like an ad. I tried below code but it's not changing the image, it shows cached image. What's wrong with my code.



protected override void OnNavigatedTo(NavigationEventArgs e)
{
ChangeImage();
var ForcedAdtimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(60) };
ForcedAdtimer.Tick += (ss, ee) => ChangeImage();
ForcedAdtimer.Start();
}

private void ChangeImage()
{
txt.Text += "Img Changed - " + DateTime.Now.ToString() + Environment.NewLine;
Nullify();
var bmp = new BitmapImage();
bmp.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
bmp.UriSource = new Uri("http://myserver.net/myImage.png");
img.Source = bmp;
}

private void Nullify()
{
BitmapImage bitmapImage = img.Source as BitmapImage;
if (bitmapImage != null)
{
bitmapImage.UriSource = null;
}
img.Source = null;
}


No comments:

Post a Comment