I have a winform which have several combo boxes and a gridview.
Initially I am creating the gridview with Rows and Columns and no data filled in with.
The filling data to grid is a long running task which will loop through all rows and read column header and depending on that it will apply different color and data to each cell.
What I am trying to achieve is to load the grid as above in form load event, and after the form loaded start filling data to grid so user can see what happening. Same things apply to the combo box value change since I will load data according to the combo value.
What I have tried is something like this...
In form load I am calling method
private void LoadForm()
{
DataBind(); // this will load the initial grid without cell data
this.BeginInvoke((MethodInvoker)this.LongRunningProcess1);
this.BeginInvoke((MethodInvoker)this.LongRunningProcess2);
}
But still it taking long time and I don't have the responsive UI.
I also tried something like this but no luck....
ThreadStart ts = LongRunningProcess1;
Thread t1 = new Thread(ts);
t1.Start();
Also using a background worker to complete the long running operation causes "Cross thread operation" issue.
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
LongRunningProcess1();
LongRunningProcess2();
}
Any help to make this working is appreciate..
Thanks
UPDATE
I found a really cool solution Updating Your Form from Another Thread without Creating Delegates for Every Type of Update
Thanks for the answers!!!