C# Programming
04-02-2009, 06:44 AM
I have a form with a particularly slow loading process. To acheive a more responsive UI I decided to use a seperate thread to load the data and populate the datagridview.
If called direct the form takes 10 secondes to display.
I have a separate method called LoadGrid to do that work.
The following is called in the form_load method
Thread oThread = new Thread(new ThreadStart(LoadGrid));
oThread.IsBackground = true;
oThread.Start();
LoadCombos();
UIUtils.BindObject(this, cashFlow);
/pre>
My expectation is that the form will display, the user can manipulate the controls and the DGV will load 10 seconds after the form is initiated. This does not happen, I get a partial display and the form locks, 10 seconds later the form completes loading and releases the UI.
Where am I screwing it up.
The LoadGrid is correctly delegated and the thread is invoked properly,
private delegate void LoadGridDelegate();
private void LoadGrid()
{
try
{
if (this.InvokeRequired)
{
this.BeginInvoke(new LoadGridDelegate(LoadGrid), null);
}
else
{
DataTable dtAttr = cashFlow.GetAttrForCashflow(cashFlow.CashflowID);
UIUtils.dgLoad(dgAttr, dtAttr.DefaultView, "");
}
}
catch (Exception)
{ throw; }
}
Never underestimate the power of human stupidity
RAH
If called direct the form takes 10 secondes to display.
I have a separate method called LoadGrid to do that work.
The following is called in the form_load method
Thread oThread = new Thread(new ThreadStart(LoadGrid));
oThread.IsBackground = true;
oThread.Start();
LoadCombos();
UIUtils.BindObject(this, cashFlow);
/pre>
My expectation is that the form will display, the user can manipulate the controls and the DGV will load 10 seconds after the form is initiated. This does not happen, I get a partial display and the form locks, 10 seconds later the form completes loading and releases the UI.
Where am I screwing it up.
The LoadGrid is correctly delegated and the thread is invoked properly,
private delegate void LoadGridDelegate();
private void LoadGrid()
{
try
{
if (this.InvokeRequired)
{
this.BeginInvoke(new LoadGridDelegate(LoadGrid), null);
}
else
{
DataTable dtAttr = cashFlow.GetAttrForCashflow(cashFlow.CashflowID);
UIUtils.dgLoad(dgAttr, dtAttr.DefaultView, "");
}
}
catch (Exception)
{ throw; }
}
Never underestimate the power of human stupidity
RAH