I设计并编写了一个程序,它具有用于加载的启动画面。我在主窗体中使用了将完全关闭加载窗体并显示主窗体的线程。 这个操作大约需要5000个女士 但是当我使用程序中的线程时,在5000 MS之后,Splash Screen会消失并且主窗体将正确显示。 但在主窗体显示后1或2秒后,程序关闭并进入BreakMode!不知道为什么。 这是我的代码。也许我的代码有问题。 在此先感谢您的建议。在windows窗体中使用线程
public MainForm()
{
Thread t = new Thread(new ThreadStart(StartForm));
t.Start();
Thread.Sleep(7000);
InitializeComponent();
t.Abort();
}
public void StartForm()
{
Application.Run(new frmSplashScreen());
}
(使用Visual Studio 2015年企业) __________________________UPDATE___________________________ 我用这个方法https://stackoverflow.com/a/393870/17034,并改变了形式命名了我的。 但是,当我使用我面对BreakingMode的节目! 这让我发疯 你的建议是什么? 有什么办法可以禁用这种模式?! 这里是我的新代码:
using System;
使用System.Windows.Forms的;
using Microsoft.VisualBasic.ApplicationServices;
命名空间大学
{
static class Program
{
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
new MyApp().Run(args);
}
}
class MyApp : WindowsFormsApplicationBase
{
protected override void OnCreateSplashScreen()
{
this.SplashScreen = new frmSplash();
}
protected override void OnCreateMainForm()
{
System.Threading.Thread.Sleep(4500);
this.MainForm = new MainForm();
}
}
}
使用[内置支持启动画面](http://stackoverflow.com/a/393870/17034)而不是试图旋转自己的。 –
@HansPassant无法更正此代码而不是更改? –
原始代码没有多大意义...通常单个线程用于UI,并且您从不**在UI线程中休眠。 **你也应该避免放弃一个线程。**在一个设计合理的应用程序中,你不要使用这样的黑客。 – Phil1970