I have a Windows Store application in which I need to download a file a couple of megabytes in size.
I am trying to do this using the HttpClient.
Here is a simplification of the code:
using (var httpClient = new HttpClient())
{
var request =
await httpClient.SendAsync(
new HttpRequestMessage(
HttpMethod.Get,
"http://openpandora.info:8080/Battlefield%204%20-%20Fishing%20in%20Baku%20-%20Xbox%20One.mp4"),
HttpCompletionOption.ResponseHeadersRead);
var outputFile =
await
ApplicationData.Current.LocalFolder.CreateFileAsync(
"test.data",
CreationCollisionOption.ReplaceExisting);
using (var outputStream = await outputFile.OpenStreamForWriteAsync())
{
await request.Content.CopyToAsync(outputStream);
}
}
The sample code provided here is downloading a 2GB file for illustration purposes.
The issue is the following. If the client has no internet connection when the app is started, the code throws an exception as expected. However, if the client loses internet connectivity while the download is running no exception is thrown and the code will never execute beyond the code block. If the client encounters no connection problems during download, the code works fine.
Any insight on why this is the case?