-
Form_Load event
When opening a form, I am loading data into a few combo boxes from an Oracle database.
I make a call to a class that load the data from the Form_Load event.
The form hangs and is not fully drawn until my data fetching is complete.
I used to have this problem in VB but I used the .Show method then, at the begining of the Form_Load event to show the form before getting data from the database which solved that.
I tried this in C# but it doesn't seem to work.
Any idea's on how I can show the form fully and have the data load whilst it is shown.
-
You can load the data in a seperate thread.
Code:
using System.Threading;
// ....
class myForm : Form
{
public void LoadDatabase()
{
// ... do stuff
}
public void myForm_Load()
{
Thread t = new Thread(new ThreadStart(LoadDatabase) );
t.Start();
}
}
-
also, if u wanto to create controls in the form in that method, u cant as u have to create another method that does that job and u must call it as this.BeginInvoke(<delegate pointing to the method>, <args if any>); otherwise u'll get an error in the threads