I got that downloader code running on Windows 10 IoT Core which tries to download a file to the applications local folder if it does not exist yet. If it does, it should return the path to that file.
Spoiler: The code snippet itself is working, see below.
private async Task<string> GetAsync(string url)
{
url = WebUtility.UrlDecode(url);
string fileName = Path.GetFileName(url);
var folder = ApplicationData.Current.LocalFolder;
var destinationFile = await folder.CreateFileAsync(fileName, CreationCollisionOption.OpenIfExists);
if (new FileInfo(destinationFile.Path).Length > 0)
return destinationFile.Path;
var downloader = new BackgroundDownloader();
var download = downloader.CreateDownload(new Uri(url), destinationFile);
await download.StartAsync();
return destinationFile.Path;
}
Now, when the file does not exist, the code is running until line await download.StartAsync()
. From there, it never returns.
In the folder, an empty file with the given name is existent but only 0kb in size - that one's created implicitly while calling CreateFileAsync()
before (and that's why I check for .Length
to check the file existence).
Now comes the thing: That code is never returning, but if I kill the application (after enough time), the file gets written to disk, so the download apparantly succeeded but it did not "flush" to the file system. That does not happen if I do not kill the app, so refreshing the Windows Explorer view or looking for the file properties does not show any change in size.
I'm getting crazy on this, could somebody give me a hint? All the tips and hints from articles like those here did not work on the Pi:
- BackgroundDownloader.GetCurrentDownloadsAsync returns completed downloads
- Check progress of download operation which started in background task
- MSDN: Background transfers: Post processing
Setup
- Raspberry Pi 3
- Windows 10 IoT Core 10.0.15063.0
- Wired Ethernet connection
- App capabilities (Package.appxmanifest)
- Internet (Client & Server)
- Internet (Client)
- Private Networks (Client & Server)
- Removable Storage