GetFileFromApplicationUriAsync似乎永远挂起

时间:2013-06-25 04:51:27

标签: c# windows-8 windows-runtime microsoft-metro windows-store-apps

我正在尝试从文件中读取数据,并且GetFileFromApplicationUriAsync,大多数时候只是永远挂起,任何想法为什么会发生这种情况。我正在模拟器上调试应用程序。

一对夫妇注意到:

BaseLocalFolder = "ms-appdata:///local/";
Uri baseUri = new Uri(BaseLocalFolder);
Uri cardsUri = new Uri(baseUri, Path.Combine(set,"cards.ccc"));
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(cardsUri);

using (IInputStream stream = await file.OpenSequentialReadAsync())
{
    using (StreamReader rdr = new StreamReader(stream.AsStreamForRead()))
    {
        var cardArray = Windows.Data.Json.JsonArray.Parse(rdr.ReadToEnd());

        foreach (Tables.Card card in cardArray.ToCards())
        {
            _cards.Add(card.ToCardViewModel());
        }
    }
}

更新: 在我根据建议更改了代码后,我开始遇到与ReadTextAsync()相同的问题,一旦它遇到该行它永远停留在那里,我永远不会得到字符串。

StorageFile file = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync(Path.Combine(set, "cards.ccc"));

            try
            {

                string allCards = await Windows.Storage.FileIO.ReadTextAsync(file);

                var cardArray = Windows.Data.Json.JsonArray.Parse(allCards);
                foreach (Tables.Card card in cardArray.ToCards())
                {
                    _cards.Add(card.ToCardViewModel());
                }
            }
            catch (FileNotFoundException err)
            {
                string s = "";
            }

0 个答案:

没有答案