我有一个带有多个控件的表单(代码中的complexForm),需要一些时间来加载。所以我决定放入一个单独的线程以减少初始加载时间。除了等待表单上的标签控件(代码中的Form1)最初没有显示外,一切正常;就在 Form1 关闭前一秒钟。所以我的问题是,为什么标签控件不显示?
[STAThread]
static void Main()
{
Thread thread = new Thread(delegate()
{
var wait = new Form1(); //simple form with a label control with text "please wait"
wait.Show();
var complexUI = new complexForm();// this takes long time to load
wait.Dispose();// it will go off even without this method
// MessageBox.Show("loaded");
});
thread.SetApartmentState(ApartmentState.STA);
thread.Priority = ThreadPriority.Highest;
thread.IsBackground = true;
thread.Start();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new main());
}