private void cmdSales_Click(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
timer2.Start();
}
private void timer2_Tick(object sender, EventArgs e)
{
TimeSpan ts = DateTime.Now.Subtract(startDate);
string sTime =" ..." + ts.Minutes.ToString("00") +
":" + ts.Seconds.ToString("00") +
":" + ts.Milliseconds.ToString("000");
toolStripStatusLabelTime.Text = sTime;
if (toolStripProgressBar1.Value ==
toolStripProgressBar1.Maximum)
{
toolStripProgressBar1.Value = 0;
}
toolStripProgressBar1.PerformStep();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
toolStripStatusLabel1.Text = "Loading ... " +
"Thanks for your patience";
frmSales objfrmSChild = frmSales.GetChildInstance();
[B] objfrmSChild.MdiParent = this;
[/B] objfrmSChild.Show();
objfrmSChild.BringToFront();
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
toolStripProgressBar1.Value = 100;
toolStripStatusLabel1.Text = "";
toolStripProgressBar1.Value = 0;
timer2.Stop();
toolStripStatusLabelTime.Text = "";
}
Progress bar is on the MDI parent form and i would like the progress bar to run after clicking on the button and when the child is loaded the progress bar will stop.
somehow i face problem when comes to "objfrmSChild.MdiParent = this;". Error msg : "Cross-thread operation not valid: Control 'frmContainer' accessed from a thread other than the thread it was created on."
How can i prevent this from happening ?