保存到“下载”文件夹,DataWriter.FlushAsync 挂起 90 秒
本文关键字:FlushAsync DataWriter 挂起 文件夹 下载 保存 | 更新日期: 2023-09-27 18:34:22
代码:
private async Task<int> Save()
{
StorageFile file = await DownloadsFolder.CreateFileAsync("a.exe");
IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite);
DataWriter writer = new DataWriter(stream);
byte[] buffer = new byte[4096];
writer.WriteBytes(buffer);
await writer.StoreAsync();
await writer.FlushAsync(); //Hang for a long time
writer.Dispose();
return 1001; //eventually it can get to this line, no exception is thrown
}
编辑:
它在Win8 CP内部版本8250上找到,升级到内部版本8375后,问题消失了。所以我想这是一个已经在 winrt 或 win8 中修复的错误。
你可以尝试更多类似的东西:
using (var fs = await file.OpenAsync(FileAccessMode.ReadWrite))
{
using (var outStream = fs.GetOutputStreamAt(0))
{
using (var dataWriter = new DataWriter(outStream))
{
byte[] buffer = new byte[4096];
dataWriter.WriteBytes(buffer)
await dataWriter.StoreAsync();
dataWriter.DetachStream();
}
await outStream.FlushAsync();
}
}