Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I have This app with a MainForm that has a few buttons on it. and the buttons would do time consuming tasks that includes working with MainForm UI.
I decided to Create a MainFormHost where it is a form with a tab control which under each tab I create an instance of my MainForm and host it there. And so far everything was ok. The problem is when I click on a button on MAinForm1 it starts working fine but as soon as I click on a button on MainForm2 the process of MainForm1 button gets queued behind the MainForm2 process.

What I have tried:

This is how im creating my Forms
C#
MainForm GetMainFrom(TabPage tabPage)
{
tabPage.Invoke(new Action(() =>
{
    mainForm = new MainForm();
    mainForm.TopLevel = false;
    mainForm.FormBorderStyle = FormBorderStyle.None;
    mainForm.Dock = DockStyle.Fill;

    _mainForms.Add(mainForm);
    tabPage.Controls.Add(mainForm);
    mainForm.Show();

}));
}


And then call the method:

C#
var mainFormThread = new Thread(() =>
{
    mainForm = GetMainFrom(tabPage);
});

mainFormThread.SetApartmentState(ApartmentState.STA);
mainFormThread.Start();




If it can be of any help, Im ok with writing the host app in WPF.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900