0

I'm writing a Windows Phone application, and it needs to download very large mp3 files, and save them to isolated storage. I've got all the code for this working, and I tested it with smaller files, but now using the actual files and monitoring what the code is doing using the debug output, I've realized that the threads are actually exiting half way through downloads, and files never actually finish downloading.

Is there a reason for this happening, and if so, what can I do to prevent this?

AllFallD0wn
  • 551
  • 7
  • 23

2 Answers2

2

How long does it timeout after? If you are using HttpWebRequest to download the file, the default time out is 100,000ms (100 seconds). This can be changed as simply as inserting:

HttpWebRequest.Timeout = 10;

Obviously setting your own timeout (in milliseconds!) and attaching it to your WebRequest :)

If your not using HttpWebRequest, let me know what you are using and i'll try my best to hep you out :)

  • I am using HttpWebRequest, however, I can't find the property .Timeout? – AllFallD0wn Nov 26 '12 at 00:14
  • @AllFallD0wn Take a look at http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx and http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.timeout.aspx I don't have the WP7 SDK installed any more so can't have a play myself sadly :( – ConnorRoberts Nov 26 '12 at 13:11
0

WP's internal memory and process management takes care about this. If you spawned a thread from your app which downloads a lot of data in the background OS will drop it off when those resources (by most chance memory) becomes needed for other processes.

You can do two things, depending on your approach for download:

  1. To periodically save buffer chunks in IsolatedStorage when buffer reaches certain size, thus limiting memory usage of the thread.
  2. Implement download thread as BackgroundTask, which should allow "endless" execution.
Igor Perić
  • 171
  • 1
  • 8
  • Am I right in think that a ScheduledAgent is a background task, and if so, the download is already a background task, yet the 3 threads keep exiting halfway through download. – AllFallD0wn Nov 26 '12 at 00:16
  • I didn't time it exactly, but it wasn't 10 minutes. More like 4, maybe 5? – AllFallD0wn Nov 26 '12 at 00:25