1

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

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。

无论如何,所有帮助将不胜感激:)

4

1 回答 1

5

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

于 2013-04-25T05:58:40.807 回答