我需要在我的程序启动时创建一个数据库/检查它的存在。ApplicationData.Current.LocalFolder GetFile同步
public async Task CopyDatabaseIfNotExists(string dbPath)
{
var nExpectedFolder = IsolatedStorageFile.GetUserStoreForApplication();
try
{
await ApplicationData.Current.LocalFolder.GetFileAsync(dbPath); //nExpectedFolder.GetFileAsync(dbPath);/// ApplicationData.Current.LocalFolder.GetFileAsync("preinstalledDB.db");
// No exception means it exists
return;
}
catch (System.IO.FileNotFoundException)
{
// The file obviously doesn't exist
}
(... some other stuff)
我的应用程序不能也不应该在测试完成之前运行。
因此,我想改变我的呼叫是同步的。
不过,我只看到
ApplicationData.Current.LocalFolder.GetFileAsync
.GetFile不存在。
什么样的方式使呼叫同步?
我相信处理这个问题的正确方法是从其调用方法使用此方法await。在使用调用方法之前,一直在调用范围链,直到你从构造函数调用。或者使用“异步无效”方法来调用它,如果你必须同步运行它。 [link] https://msdn.microsoft.com/en-us/magazine/jj991977.aspx –