Quantcast
Channel: CameTooFar
Viewing all articles
Browse latest Browse all 45

How to: Pause/Resume BackgroundTransferRequest or BackgroundTransferService in Windows Phone

$
0
0

Recently, I came across a requirement where I need to perform a background download; along with pause and resume support in Windows Phone 8. The first part is quite easy and straightforward. You can create a BackgroundTransferRequest and add it to the BackgroundTransferService. Done! The BackgroundTransferService class will take care of the background operations for you.

Now, coming to the pause-resume support. I think with current stock APIs for background operations, it's not possible to perform a pause-resume. Why it's so? Because few HTTP headers - If-Modified-Since, If-None-Match, If-Range, Range and Unless-Modified-Since are reserved for BackgroundTransferRequest. From these reserved headers, Range header can be used to download a resource partially by specifying the starting and ending bytes, something like Range: bytes=500-999.

Being said, you can implement a pause-resume or partial download using WebClient class and specifying HTTP Range header value. Unfortunately, this runs in foreground only. Means, while downloading a resource you "should" remain in the UI itself.

Hope this helps.

Thanks


Viewing all articles
Browse latest Browse all 45

Trending Articles