I am doing some MultiThreading but the form pauses on load.
I am trying to display the form, and then in the background it should populate the combobox without pausing the form.
On my Form_Load event, I have this:
private void frmIni_Load(object sender, EventArgs e)
{
Application.DoEvents();
Thread threadOne = new Thread(GetServers);
threadOne.Start();
}
In my GetServers() method:
private void GetServers()
{
cboServer.BeginInvoke(
(Action)(() => {
servers = SmoApplication.EnumAvailableSqlServers(false);
Thread.Sleep(1);
foreach (DataRow server in servers.Rows)
{
cboServer.Properties.Items.Add(server["Name"]);
Thread.Sleep(1);
}
}));
}
What am I missing here? The form should not pause, it should work and then eventually when the thread completes, it should just populate the combobox.