【发布时间】:2014-02-10 08:08:37
【问题描述】:
我遇到了一些问题。这是我的代码:
private async void SetCollectionForGame()
{
maincollection = new Dictionary<string, string>();
bool statebase = await CheckExistingBase();
if (statebase)
{
//If file exists...
basefile = await folder.GetFileAsync(basefilename);
}
else
{
//If file does not exist...
SaveBaseFileAsync(filelink, folder, basefilename);
basefile = await folder.GetFileAsync(basefilename);
}
string content = String.Empty;
content = await FileIO.ReadTextAsync(basefile, Windows.Storage.Streams.UnicodeEncoding.Utf8);
//When the app first starts, I get an exception on the next line,
//because the variable "content" is null.
maincollection = JsonConvert.DeserializeObject<CollectionModel>(content).collection;
}
有人知道如何解决这个问题吗?文件下载工作正常,下载后文件在文件夹中创建。
【问题讨论】:
-
你为什么不只检查空值?
-
很简单,因为我在应用程序启动时需要这个文件。问题是为什么它在应用首次启动时为空。
-
CheckExistingBase()可能有问题,即使文件不存在,它也会返回true?只是猜测
标签: c# windows-runtime async-await windows-8.1 c#-5.0