KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
There are a bunch of questions about this already on this site and other forums, but I've yet to find a solution that actually works. Here's what I want to do: In my WPF app, I want to load an image. The image is from an arbitrary URI on the web. The image could be in any format. If I load the same image more than once, I want to use the standard windows internet cache. Image loading and decoding should happen synchronously, but not on the UI Thread. In the end I should end up with something that I can apply to an <Image>'s source property. Things I have tried: Using WebClient.OpenRead() on a BackgroundWorker. Works fine, but doesn't use the cache. WebClient.CachePolicy only affects that particular WebClient instance. Using WebRequest on the Backgroundworker instead of WebClient, and setting WebRequest.DefaultCachePolicy. This uses the cache properly, but I've not seen an example that doesn't give me corrupted-looking images half the time. Creating a BitmapImage in a BackgroundWorker, setting BitmapImage.UriSource and trying to handle BitmapImage.DownloadCompleted. This seems to use the cache if BitmapImage.CacheOption is set, but there doesn't seem to be away to handle DownloadCompleted since the BackgroundWorker returns immediately. I've been struggling with this off-and-on for literally months and I'm starting to think it's impossible, but you're probably smarter than me. What do you think?
Tags (comma-separated)
Save Edits
Cancel