0

编码:

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 build 8250上发现,升级到build 8375后问题消失。所以我猜这是一个已经在winrt或win8中修复的错误。

4

1 回答 1

1

您可以尝试更多类似的方法:

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();
    }
}
于 2012-05-17T16:16:05.433 回答