I am working on a program that reads a text file and stores parts of it in chunks in an array and then (this is the theory) parses the text in each block (index) and populates a series of textboxes with the parsed data. Because each block will contain data of the same fields, my idea is to open a new window when the user closes the current one and process the data in the next index. This will continue until the array’s length has been reached.
My issue is that I don’t know to open a new window and increment the array’s index for an unknown number of indices.
This is my code for storing the chunks:
using (StreamReader r = new StreamReader(fname))
{
string input = File.ReadAllText(fname);//read through file
String[] vArray = input.Split(new string[] { "BEGIN:VCARD" }, StringSplitOptions.None); ...
and then my code for processing it is:
int i;
parser(vArray[1]);
MainWindow a = new MainWindow();
a.parser(vArray[2]);
a.Show();
for (i = 1; i < vArray.Length - 2; i++)
{
a.Closing += delegate(object sender, System.ComponentModel.CancelEventArgs e)
{
MainWindow b = new MainWindow();
b.parser(vArray[i++]);
b.Show();
};
}
This seems really obvious, but I just can’t seem to get it 🙂 Any help would be welcomed and appreciated.
One issue seems that you subscribe to the Closing event on the first form many times, when that forms all the other forms will pop up at once.
I would recommend using
ShowDialoginstead ofShow.ShowDialogblocks execution until the opened form is closed. Then you can remove any Closing events.Then you can simplify everything to a
foreachloop too.