I'm trying to make a cross-platform WinForms software, with a GUI and a 3D window inside of it. Currently, I have a TabControl with two tabs, and the second one needs to contain the GLControl (3D Window). However, when I switch to the second tab, the program hangs while the GLControl is loaded, presumably because they are on the same thread.
I've tried resolving it with a BackgroundWorker like this:
private void onTabSwitch(object sender, EventArgs e)
{
if (tabControl.SelectedIndex == 1)
if (area3D == null)
this.worker.RunWorkerAsync();
}
...
...
...
private void worker_DoWork(object sender, DoWorkEventArgs e)
{
area3D = new GLControl();
area3D.Load += new EventHandler(area3D_Load);
area3D.Paint += new PaintEventHandler(area3D_Paint);
area3D.BackColor = Color.Black;
area3D.Size = new Size(438, 435);
area3D.Location = new Point(200, 0);
this.Invoke((MethodInvoker)delegate
{
secondTab.Controls.Add(area3D); // runs on UI thread
});
}
But it still hangs, because the second tab is still on the main GUI thread. How can I resolve this?
Bottomline, I need a 3D window in another tab that will load asynchronously, or just not cause my program to hang.