WPF BitmapImage objects failing to raise events correctly
I have been having issues with the DownloadCompleted and DownloadFailed events failing to fire correctly from the BitmapImage object. This is a huge issue as the asynchronous processing of images is central to many types of WPF apps. Having events failing to fire correctly will likely have a rather large negative impact on these apps.
The problem is easily recreated. Iterate through any number of BitmapImage creations, subscribe to the DownloadCompleted and DownloadFailed events, and track the number of DownloadCompleted + DownloadFailed events which fire vs the number of events subscribed to. Those numbers should always add up.
In my testing the events only fire correctly on the first full iteration. After the first iteration they will never fire again. Ever. The event subscriptions are simply going into a black hole. Verify for yourself. You can create your own app or just use my test app.
I’d be interested to hear the results of everyones testing.
-MGE
October 12th, 2006 at 11:53 pm
Hi Michael,
I downloaded your test app and looked through (and debugged) what you are doing and the behavior you are seeing is expected. The reason is during the 2nd and future iterations of the app creating BitmapImage(s), nothing is downloaded. The first time around, the image is downloaded and then put in our internal cache. Afterwards, each creation just hits our cache and thus there is nothing to download. Notice how pressing Go the first time around takes much longer than pressing it the 2nd time… Its almost instantaneous. We only fire the events when we are downloading images off the network… One good way to check if something is being asynchronously downloaded is to use the IsDownloading property on BitmapImage.
If you have further questions about this, please do not hesitate to email me and I’ll be glad to help.
October 13th, 2006 at 5:00 pm
Thank you for clearing this up! It was my (obviously faulty) understanding that the events would fire regardless of if the images had already been cached or not. This also fixes an issue I had in the Infinite Image Engine app where I would download 100 random images at a time and 10-15 of the events would not fire-these are obviously repeat images that were already in the cache. Very easy to check for now that the event firing process is clear.
Thanks for taking the time.
-MGE