我有一个方法可以返回文件的正确路径
StorageFile newFile = null;
try
{
string pth = Path.Combine(ApplicationData.Current.LocalFolder.Path, dbPath);
newFile = StorageFile.GetFileFromPathAsync(pth).GetResults(); ;
}
catch (FileNotFoundException) { newFile = null; }
if (newFile == null)
{
string pth = Package.Current.InstalledLocation.Path + @"\Scriptures\" + dbPath;
StorageFile oldFile = StorageFile.GetFileFromPathAsync(pth).GetResults();
newFile = oldFile.CopyAsync(ApplicationData.Current.LocalFolder, dbPath, NameCollisionOption.FailIfExists).GetResults();
}
if (newFile == null) { throw new FileNotFoundException("Database File not Found"); }
return newFile.Path;
但是,有时我会遇到错误
StorageFile.GetFileFromPathAsync(pth).GetResults()
抛出的错误是:
StorageFile newFile = null;
try
{
string pth = Path.Combine(ApplicationData.Current.LocalFolder.Path, dbPath);
newFile = StorageFile.GetFileFromPathAsync(pth).GetResults(); ;
}
catch (FileNotFoundException) { newFile = null; }
if (newFile == null)
{
string pth = Package.Current.InstalledLocation.Path + @"\Scriptures\" + dbPath;
StorageFile oldFile = StorageFile.GetFileFromPathAsync(pth).GetResults();
newFile = oldFile.CopyAsync(ApplicationData.Current.LocalFolder, dbPath, NameCollisionOption.FailIfExists).GetResults();
}
if (newFile == null) { throw new FileNotFoundException("Database File not Found"); }
return newFile.Path;
我究竟做错了什么?我是 c# 和线程的新手,这个错误让我很生气,因为有时它有效,有时却无效。请帮忙!