CreateFolderAsync()抛出FileNotFoundException [英] CreateFolderAsync() throwing FileNotFoundException

查看:70
本文介绍了CreateFolderAsync()抛出FileNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在用户的音乐库中创建文件夹和文件。我的应用程序在清单中声明了musicLibrary功能。

My application creates folders and files in the user's music library. My app declares the musicLibrary capability in the manifest.

它将在音乐中创建子文件夹像这样的库:

It will create subfolders in the Music library like this:

try

{

IStorageFolder subFolder =
await KnownFolders.MusicLibrary .CreateFolderAsync(
folderName,CreationCollisionOption.OpenIfExists);

IStorageFolder subFolder = await KnownFolders.MusicLibrary.CreateFolderAsync( folderName, CreationCollisionOption.OpenIfExists);

}

catch(Exception ex)

catch(Exception ex)

{

//异常记录

}

在测试应用程序时,我偶尔会遇到System.IO.FileNotFoundException。 />
消息:系统找不到指定的文件。 (来自HRESULT的异常:0x80070002)
$
InnerException:null

While testing the app, I sporadically encounter a System.IO.FileNotFoundException.
Message: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
InnerException: null

由于我无法重现此行为,我想知道在调用CreateFolderAsync时可能会导致此异常的原因()?

Since I am unable to reproduce this behavior, I wonder what could potentially cause this exception when calling CreateFolderAsync()?

推荐答案

您的代码很可能被困在"await ... CreateFolderAsync"的虚假安全性中。在一个方法调用中。

It is most likely that your code is trapped in the false security of the "await ... CreateFolderAsync", within a method call.

Andrei Marukovich在这里解释得非常出色:
http://lunarfrog.com/blog/2012/01/23/simplicity-of-async-and-await/

Andrei Marukovich explains this brilliantly here: http://lunarfrog.com/blog/2012/01/23/simplicity-of-async-and-await/

如果确认,则必须重新安排代码以考虑他的发现。

If this is confirmed, you will have to rearrange the code to take his findings into account.


这篇关于CreateFolderAsync()抛出FileNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆