I am working with the backgroundworker and the datagridview. I have noticed a difference.
I have put a loop that puts a value to one cell in the datagrid first in a buttonevent.
After this loop is finished wich creates a timer textfile that tells how long the process did take, the code executes the backgroundworker that has a Sleep(10000) before the very same loop executes with a timer and put this to another file under C:\\
Loop under button takes: 26 seconds
Loop in backgroundworker takes: 36 seconds
Why is this difference and what can I do about it as the backgroundworker needs to do it as fast as in the buttonevent ?
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
time_t now = time(0);
struct tm* tm = localtime(&now);
ofstream Timer1;
Timer1.open("C:\\Timercount1.txt");
int Minute;
int Second;
Minute = tm->tm_min;
Second = tm->tm_sec;
[B]for( int s = 0; s < 111111111; s++ )
{
dataGridView1->Rows[0]->Cells[1]->Value = "Value1";
}[/B]
time_t now2 = time(0);
struct tm* tm2 = localtime(&now2);
Timer1 << "Start " << Minute << "." << Second << " " << "End " << tm2->tm_min << "." << tm2->tm_sec;
Timer1.close();
backgroundWorker1->RunWorkerAsync();
}
private: System::Void backgroundWorker1_DoWork(System::Object^ sender, System::ComponentModel::DoWorkEventArgs^ e)
{
time_t now = time(0);
struct tm* tm = localtime(&now);
ofstream Timer1;
Timer1.open("C:\\Timercount2.txt");
int Minute;
int Second;
for( int w = 0; w < 5; w++ )
{
w = w - 1;
Thread::Sleep(10000); //10 seconds
for( int i = 0; i < 5; i++ )
{
i = i - 1;
Minute = tm->tm_min;
Second = tm->tm_sec;
[B] for( int s = 0; s < 111111111; s++ )
{
dataGridView1->Rows[0]->Cells[1]->Value = "Value1";
}[/B]
time_t now2 = time(0);
struct tm* tm2 = localtime(&now2);
Timer1 << "Start " << Minute << "." << Second << " " << "End " << tm2->tm_min << "." << tm2->tm_sec;
Timer1.close();
break;
}
break;
} //New for loop that updates/checks ONCE 10 second
}