This is kind of a 2 part question
1) Is there a max number of HttpWebRequests that can be run at the same time in WP7?
I’m going to create a ScheduledTaskAgent to run a PeriodicTask. There will be 2 different REST service calls the first one will get a list of IDs for records that need to be downloaded, the second service will be used to download those records one at a time. I don’t know how many records there will be my guestimage would be +-50.
2.) Would making all the individual record requests at once be a bad idea? (assuming that its possible) or should I wait for a request to finish before starting another?
Having just spent a week and a half working at getting a BackgroundAgent to stay within it’s memory limits, I would suggest doing them one at a time.
You lose about half your memory to system libraries and the like, your first web request will take another nearly 20%, but it seems to reuse that memory on subsequent requests.
If you need to store the results into a local database, it is going to take a good chunk more. I have found a
CompiledQueryuses less memory, which means holding a single instance of your context.Between each call I would suggest doing a
GC.Collect(), I even add a shortThread.Sleep()just to be sure the process has some time to tidying things up.Another thing I do is track how much memory I am using and attempt to exit gracefully when I get to around 97 or 98%.
You can not use the debugger to test memory limits as the debug memory is much higher and the limits are not enforced. However, for comparative testing between versions of your code, the debugger does produce very similar result on subsequent runs over the same code.
You can track your memory usage with
Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsageandMicrosoft.Phone.Info.DeviceStatus.ApplicationMemoryUsageLimitI write a status log into
IsolatedStorageso I can see the result of runs on the phone and useScheduledActionService.LaunchForTest()to kick the off. I then useShellToastnotifications to let me know when the task runs and also when it completes, that way I can launch my app to read the status log without interrupting it.