我对表单加载进行了一些检查,但它将表单锁定一段时间(千分之几秒).出于这个原因,我想显示一条消息,如"正在加载应用程序..",但我不知道我是如何做到的.我希望这清楚!非常感谢任何帮助.提前致谢.
Chr*_*ain 10
理想情况下,您要做的是在后台线程上执行检查,以便不阻止UI线程.看看BackgroundWorker类.
您应该将检查挂钩到后台工作程序的DoWork事件,并RunWorkerAsync()从Form_Load事件中调用BackgroundWorker的方法来启动后台工作.
像这样的东西(注意,这是未经测试的):
BackgroundWorker bw = new BackgroundWorker();
public void Form_Load(Object sender, EventArgs e) {
// Show the loading label before we start working...
loadingLabel.Show();
bw.DoWork += (s, e) => {
// Do your checks here
}
bw.RunWorkerCompleted += (s, e) => {
// Hide the loading label when we are done...
this.Invoke(new Action(() => { loadingLabel.Visible = false; }));
};
bw.RunWorkerAsync();
}
Run Code Online (Sandbox Code Playgroud)