windows-phone-8.1 – 如何避免StorageFile.CopyAsync()在复制大文件时抛出异常?

前端之家收集整理的这篇文章主要介绍了windows-phone-8.1 – 如何避免StorageFile.CopyAsync()在复制大文件时抛出异常?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我将通过StorageFile.CopyAsync()方法将一些文件从视频库复制到我的应用程序存储,但如果文件的大小超过1GB,则会抛出异常,如下所示:

Type: System.Runtime.InteropServices.COMException Message: Error
HRESULT E_FAIL has been returned from a call to a COM component.
Stacktrace: at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

如何导入大文件,是否有解决此问题的解决方案?

我会尝试通过缓冲区复制它 – 例如像这样:
private async Task CopyBigFile(StorageFile fileSource,StorageFile fileDest,CancellationToken ct)
{
   using (Stream streamSource = await fileSource.OpenStreamForReadAsync())
   using (Stream streamDest = await fileDest.OpenStreamForWriteAsync())
       await streamSource.CopyToAsync(streamDest,1024,ct);
   return;
}
原文链接:https://www.f2er.com/windows/363450.html

猜你在找的Windows相关文章