获取本地音乐库中的文件夹及文件显示到界面的时候,设置断点一步步跟踪是正常获取到,但如果去掉了断点就会出错,菜鸟寻求高手指点,如果解决?下面是代码
List<FileInfo> DatailInfo = new List<FileInfo>();
public List<FileInfo> GetLocalDetailInfo(string strDitroyName) { GetAllFolder(strDitroyName); return DatailInfo;///执行完这里就会出错,一步步跟踪的时候这里DatailInfo可以得到数据,但不设置断点,这里DatailInfo的count是0.这个时候就出现了错误。 }
private async void GetAllFolder(string strDitoryName) { IAsyncOperation<IReadOnlyList<IStorageItem>> istroageItem = null;
istroageItem = KnownFolders.MusicLibrary.GetItemsAsync();
IReadOnlyList<IStorageItem> ItemList = istroageItem.GetResults();
if (ItemList.Count <= 0) return;
foreach (var item in ItemList) { string strName = item.Name; string strPath = item.Path; string strDate = item.DateCreated.ToString("yyyy-MM-dd"); string strType = item.Attributes.ToString();
ulong lSize = (await item.GetBasicPropertiesAsync()).Size;//.GetResults().Size; string strSize = "";
if (strType.Equals("Directory")) { DatailInfo.Add(new FileInfo() { FileName = strName, FileType = "文件夹", FileSize = "", SmallImageUrl = "ms-appx:///Assets/Images/Icons/folder.png", BigImageUrl = "ms-appx:///Assets/Images/Icons/folder.png", FileUrl = strPath, CreateTime = strDate }); }
}
}
错误信息:未处理InvalidoperationException
在意外的时间调用了方法(异常来自: HRESULT: Ox8000000E)