hi,
i put together this code to read a text file line by line, split the resulting string into the 4 values and send these values to four text-boxes. during each cycle of that while loop it's suppose to initialize the backgroundworker_dowork, which will read the values and use them(and start a long loop and stuff).
The first and obvious problem i have is that when i run this i get an error saying that this backgroundworker is already busy and can't handle another task.
The part that's supposed to read text works as far as i can tell from using breakpoints while debugging but i'm not sure if it behaves like i think it does. (only the last set of values appears on the form, i'm not sure if the rest ever get painted to the form, i know however that they are read from using a breakpoint where this happens)
- I would like some advice on how to get this thing to work. Every set of values should be displayed, the backgroundworker initated, when it finishes it's job the next values read, displayed and so on.
This is the first app in which i use the bgworker, so i dunno much about it yet. I think it has some way of reporting that it has finished it's work. Should i use that as a condition to move on with the while loop?
sorry if what i wrote didn't make sense in some places, pls lemme know so i can try to explain better. i'm using VS 2010 express, c++, not total beginner but not too much experience:P
thanks for any help you can give with this:)
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
String^ path = "<path>\\My_file.txt";
StreamReader^ sr = gcnew StreamReader( path );
array<String ^> ^ values = gcnew array<String ^>(4);
int i2=0;
System:String^ Input= gcnew System::String(" ");// input;
try
{
while ((Input = sr->ReadLine()) != ".")//read until it reaches the . on the final row
{
input_box->Text = Input; //the string from the file is displayed as is
i2=i2+1; //this will count the rows that are read
counter_box->Text = i2.ToString(); //
//------------------------------------------
int j2=0;
int l2=0;
int a2=Input->Length;
values[0] = ""; //these will hold the separated numbers
values[1] = "";
values[2] = "";
values[3] = "";
//this next loop will split the string into the 4 values
for (l2 = 0; l2 < a2; l2++)
{
if (Input[l2] == '\040') //check if a space is found
{
j2++; // move on to the next word
l2++; //skip over blank space
}
values[j2] += Input[l2]; //increment the current value with the next digit
}
text_1->Text = values[0]; //send the 4 values to the form
text_2->Text = values[1];
text_3->Text = values[2];
text_4->Text = values[3];
backgroundWorker2->RunWorkerAsync();//call the DoWork event
}
}
finally
{
delete sr;
}
}
};