This code allows the form to load before the data is loaded but some of the components on the form such as buttons and the datagridview itself are "invisible" until the data is loaded.
How do I fix this problem?
private void Form1_Load(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(delegate()
{
this.Invoke(new MyDelegate(delegate()
{
ReadXml(path);
Bind();
}));
}));
t.Start();
}
private void Bind()
{
dataGridView1.DataSource = table;
}
I also have this other code which works better, but requires that I use 2 new threads. This can't be the best way to do this, can it?
private void Form1_Load(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(delegate()
{
this.Invoke(new InvokeDelegate(delegate()
{
Thread t2 = new Thread(new ThreadStart(delegate()
{
ReadXml(path);
}));
t2.Start();
t2.Join();
Bind();
}));
}));
t.Start();
}