I am trying to read an image async from a web server. I works the first time, but after the next call the image just blinks and nothing happens.
I tried other approaches but I got the same result.
How can I update the image properly?
public async void ReadNextPhoto(Image image)
{
// getimage returns a random string with the image url
var uri = new Uri("http://example.com/getimage.php");
var httpClient = new HttpClient();
// Always catch network exceptions for async methods
try
{
var result = await httpClient.GetStringAsync(uri);
var bi = new BitmapImage(new Uri(result));
image.Source = bi;
}
catch
{
// Details in ex.Message and ex.HResult.
}
}
Thank you, Jonathan
Edit: The answer from getimage.php is a string with the actual image example.com/random_image_01.jpg
Edit2: The problem is in the httpClient, it always returns the same string. Cache maybe?