Reputation: 1
I am making an iPhone app that get's its data form a WCF service which I am writing and hosting. I am using MonoTouch to write the iPhone client. I have a table on one of my screens which shows a list of items (about 100 items at the most). Each of the items has an image to be displayed on the custom cell. To save having to load all of the images initially I load the list of items upfront, then fire off a thread calling a service to retrieve each cells image in the GetCell method. Once the image is retrieved I store it in a dictionary and retrieve it from there next time the cell is rendered to save doing a second service call. This means that the image is only loaded if required, once from the service, then from the dictionary thereafter. I am using code similar to that shown in the following article;
This works well in the emulator, but when I deploy it to a test device (an iPhone 4 on local WiFi) I encounter some issues which I'm hoping somebody can help me with.
When I load the list initially all is well. When I scroll right down the list (swipe my finger upwards quickly), the device stutters quite badly. It looks like the call to the service is delaying the scroll. I have taken out the code that draws the resulting image on the cell out to discount this from the routine as I guessed this would be the culprit, but it's still quote laggy. I am calling my 'GetImage' method using the ThreadPool.QueueUserWorkItem method and am passing in a reference to my custom cell controller so I expected the call to be sent off on another thread, then the program should carry on, not interrupting the UI, but I'm wondering whether me passing in the reference to the cell controller is causing issues with it being a virtual list?
Secondly, if I scroll up and down the list quickly so that a load of calls are made and then navigate back to my previous screen to change the list criteria, it looks like I have to wait until the existing calls have been returned before I can make another one on my criteria page - which takes longer than I would like. Is there any way to discard the existing calls when I navigate away from the screen as they would no longer be needed?
Thanks in advance for any help.
Al.
Upvotes: 0
Views: 377
Reputation: 11418
We have implemented a solution which uses the ashx
http handler to return an image based on the querystring at a specific url.
We then use Miguel's Image Loader which sorts out caching etc.
I don't think that, out of the box, the ImageLoader
supports images from a WCF call, but (as Sixto Saez noted) it may be more efficient to have the images supplied as Images and not in SOAP messages.
Upvotes: 0
Reputation: 12680
Assuming that static image files will work for your use case, I'd suggest that you put all the images on your web server and make them directly accessible as a URL. To fetch the image, you'd go directly to the WebClient class and by-pass all the WCF overhead.
As a general optimization, you may want to create an HTTP based service using something like the new ASP.NET 4 Web API framework which allows going directly over HTTP instead of building a soap-based WCF service.
Upvotes: 1