不循环遍历每一行仅查看第一行c#

时间:2014-04-07 20:27:15

标签: c# asynchronous async-await messagedialog

好的,我正在为Windows 8商店制作应用程序,但是我使用MessageDialog进行错误我并不是特别确定原因但似乎当我包含MessageDialog时,foreach循环停止循环遍历每一行并仅查看第一行,所以这是我的代码;

try {
    StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
    StorageFile storageFile = await folder.GetFileAsync("students.txt");
    var text = await Windows.Storage.FileIO.ReadLinesAsync(storageFile);

    foreach (var line in text)
    {
        string name = "" + line.Split('|')[0];
        string testTaken = "" + line.Split('|')[1];

        if (your_name.Text == name)
        {
            if (testTaken == "false") 
            {
                pageTitle.Text = name + "'s test";
                enter_name_grid.Opacity = 0;
                questions_grid.Opacity = 1;
                var md = new MessageDialog("Enjoy the test");
                await md.ShowAsync();
            }
            else
            {
                var md1 = new MessageDialog("You have already taken the test");
                await md1.ShowAsync();
            }
        }
        else
        {
            pageTitle.Text = "Test";
            var md2 = new MessageDialog("You're not on the list");
            await md2.ShowAsync();
        }
    }
} catch (Exception e) {
    var mderror = new MessageDialog("{0} Exception caught: " + e);
    mderror.ShowAsync();
}

我现在真的已经走到了尽头,所以任何人都可以放弃一些亮光或提供任何帮助,我们将不胜感激!感谢

0 个答案:

没有答案