To all,
I have a GUI program (use c#), and I have create a Thread for loading
some bulk data, I also arrange the GUI program like this:
1) load a form showing "Wait for loading..." etc
2) a Thread is then created to load the bulk data
3) after the thread has completed, close the "Wait for loading" form
4) show the main form for the GUI program
The problem is that if I show the "waiting" form, that form's GUI will
not work properly (no repaint event and hangs around, ie. a blank
window), the worse thing is that the Thread may not work properly too
(actually it will stop executing, waiting for locks, maybe ??)
But if I start the Thread without showing any forms; it works
perfectly ????!
What's wrong ?? (the same things happen under .Net Compact Framework)
[code snippet for the main GUI form]
public class Trial04_02 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.ComponentModel.Container components = null;
private Trial04_01 mFrmSplash;
private Thread mThr_Main;
private System.Windows.Forms.ListBox listBox1;
private CommonEngine02 mCEng;
public Trial04_02()
{
InitializeComponent();
init ();
}
private void InitializeComponent() {}
protected void init ()
{
// 1st show splash form
this.mFrmSplash = new Trial04_01 ();
//this.mFrmSplash.Show ();
// 2nd create a thread to load sth...
// CommonEngine02 is a class containing the
// data loading function
this.mCEng = new CommonEngine02 (); this.mThr_Main = new Thread
(new ThreadStart (this.mCEng.threadTask));
this.mThr_Main.Start ();
this.mThr_Main.Join ();
this.mFrmSplash.Close ();
// 3rd other setup(s)
// get back the loaded data
System.Collections.ArrayList oArr
= this.mCEng.getArr_Data ();
for (int i=0; i<oArr.Count; i++)
{
this.listBox1.Items.Add (oArr[i]);
}
this.Show ();
}
static void Main ()
{
Application.Run (new Trial04_02 ());
}
}
}
[/code]
From Jason (Kusanagihk)