Windows ストア アプリからファイルをダウンロードできません。ダウンロードするための私の方法は次のとおりです。
private static async void DownloadImage()
{
HttpClient client = new HttpClient();
HttpResponseMessage message = await client.GetAsync("http://coolvibe.com/wp-content/uploads/2010/05/scifiwallpaper1.jpg");
StorageFolder myfolder = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile sampleFile = myfolder.CreateFileAsync("image.jpg", CreationCollisionOption.ReplaceExisting).GetResults();// this line throws an exception
byte[] file = await message.Content.ReadAsByteArrayAsync();
await FileIO.WriteBytesAsync(sampleFile, file);
var files = await myfolder.GetFilesAsync();
}
マークされた行で、次の例外が発生します。
An exception of type 'System.InvalidOperationException' occurred in ListStalkerWin8.exe but was not handled in user code
WinRT information: A method was called at an unexpected time.
Additional information: A method was called at an unexpected time.
何が原因でしょうか?