I am writing a RouteHandler as part of my MVC3 solution. It purpose is to get images and files from my cloud storage and deliver them to the browser while masking the cloud storage urls.
Everything from the "media" sub-domain gets routed to my MediaRouteHandler where I have implemented the logic to get the images.
I am struggling to get an asynchronous implementation for the HttpWebRequest. At best it behaves erratically. Sometimes bringing down the images correctly, sometimes not.
Does a standard browser load images synchronously or asynchronously? Or am I trying to do something that even the browsers don't generally do (and just wasting my time)?
i.e. If the default way a browser gets an image is from a synchronous thread, then I am happy just doing that.
Is that the case?
A bit of testing:
This is the result of my synchronous route handler. You will see that the image requests overlap, and by using fiddler to mimic modem download speeds, I can see them coming down at the same time at different speeds.
If images are requested one-by-one then actually each MediaRouteHandler
runs in its own thread. You can therefore simply perform a synchronous HttpWebRequest
for each image as nothing is blocked (client browser needs full image file anyway).
Please note that asynchronous calls can be worth considering due to performance benefits. If image data is long - you can start pushing data to client browser although not whole data was yet downloaded from your cloud storage.