【发布时间】:2018-08-04 15:55:56
【问题描述】:
是否可以只显示启动画面(不显示主窗体)?
SplashScreen splash;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
splash = new SplashScreen();
splash.Show();
BackgroundWorker backgroundWorker = new BackgroundWorker();
backgroundWorker.DoWork += BackgroundWorker_DoWork;
backgroundWorker.RunWorkerCompleted += BackgroundWorker_RunWorkerCompleted;
backgroundWorker.RunWorkerAsync();
// var mainForm = MainForm();
// Application.Run(layoutForm); // I don't want to call this from here
}
private static void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
splash.Close();
// This never gets called, coz application ended
}
private static void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 0; i <= 100; i++)
{
Thread.Sleep(100);
}
}
【问题讨论】:
-
至少,您需要调用
ShowDialog而不是Show并在此之前开始后台处理(假设简单的方法适合您)。 -
另外,您可能还想使用一些计时器来控制飞溅在快速计算机上最少显示的时间。
-
thnx @Phil1970,似乎
ShowDialog会为我解决问题.. -
我需要将我的 BackgroundWorker 代码移动到 SplashScreen Load 事件