文件读取器冻结了我的程序

本文关键字:我的 程序 结了 冻结 读取 文件 | 更新日期: 2023-09-27 18:10:44

运行以下方法时,我无法确定程序冻结的原因:

String fileName = "Drops.de";
        StreamReader streamReader = new StreamReader(fileName);
        String npcName;
        string npcID;
        string itemID;
        string itemAmount;
        string itemRarity;
        string itemName;
        while(!streamReader.EndOfStream){
            string line = streamReader.ReadLine();
            //start of block
            if(line.StartsWith("[")){
                npcName = line.TrimStart('[');
                npcName = npcName.TrimEnd(']');
                while(npcName == button1.Text){    
                while(!line.StartsWith("[/")){
                    line = streamReader.ReadLine();
                    String[] s = line.Split(' ');
                    npcID = (s[0]);
                    itemName = (s[1]);
                    itemID = (s[2]);
                    itemAmount = (s[3]);
                    itemRarity = (s[4]);
                    dataGridView1.Rows.Add(itemName, itemID, itemAmount, itemRarity);
                    /*
                    DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone();
                    row.Cells[0].Value = itemName;
                    row.Cells[1].Value = itemID;
                    row.Cells[2].Value = itemAmount;
                    row.Cells[3].Value = itemRarity;
                    dataGridView1.Rows.Add(row);*/
                    dataGridView1.Refresh();
                    line = streamReader.ReadLine();
               //MessageBox.Show(npcName);
                }
                }
            }
        }
        streamReader.Close();
    }

我怀疑这与while循环有关。然而,我很可能错了。我对编程很陌生,所以这可能是显而易见的:p。

无论如何,我们将非常感谢所有的帮助:(

文件读取器冻结了我的程序

你会退出这个循环while(npcName == button1.Text){吗?:-(