1
votes

I have in my Windows Phone app several images that are binded to uri's this causes the UI threa to get blocked when all the images are downloaded. I cant create a bitmapImage instance on a different thread because I would get an "Invalid cross thread operation" exeption.

I tried downloading the image using a WebClient but there is no constructor that accepts a stream for BitmapImage.

Any thought as to how I can accomplish downloading images in the background?

thanks

Amit

2
Can you give an exmaple of the method you are using to download and bind? - Dan Sewell

2 Answers

2
votes

In order to use a Stream to provide the content for a BitmapImage you create an instance using the default constructor then call SetSource passing the stream:-

  var bi = new BitmapImage();
  bi.SetSource(myStream);

However I think you may be re-inventing the wheel here. Take a look the link below:-

Keep a low profile (LowProfileImageLoader helps the Windows Phone 7 UI thread stay responsive by loading images in the background

0
votes

You're still on the UI thread using WebClient. If you continue with that approach, you can also consider HttpWebRequest. Here's a working sample including resolution for the invalid cross-thread access exception.

WebClient, HttpWebRequest and the UI Thread on Windows Phone 7