【发布时间】:2013-06-03 10:58:36
【问题描述】:
我遇到了一些我无法自行解决的奇怪问题...我使用线程创建了启动画面(Form3 ~ SplashScreen),不知何故在应用程序到达部件之后
thread.Abort();
(实际上会杀死线程)闪屏会一直停留在屏幕上,直到我将鼠标移到它上面,或者在其他表单(例如 Form1)上的某个位置单击它...我变得更加困惑,因为这并没有当我运行应用程序时发生在 VS 中。启动画面正在正确关闭......,它只发生在编译的 .exe 上 程序.cs
namespace ICAMReports
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
SplashScreen.cs
namespace ICAMReports
{
public partial class SplashScreen : Form
{
public SplashScreen()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
progressBar1.Increment(1);
if (progressBar1.Value == 100)
{
timer1.Stop();
}
}
}
}
Form1.cs
namespace ICAMReports
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Thread th = new Thread(new ThreadStart(splashScreen));
th.Start();
Thread.Sleep(3000);
th.Abort();
}
public void splashScreen()
{
Application.Run(new SplashScreen());
}
//this where the rest of code is placed....
}
}
任何线索,为什么会发生这种情况或如何解决这个问题?
截图:
【问题讨论】:
-
我不知道你怎么能在同一个问题中拥有
thread.Abort和“正常关闭” -
thread.Abort 实际上是 th.Abort();在 Form1.cs
-
据我所知;线程.睡眠(3000); -> 停止当前线程,th.Abort(); -> 杀死线程(并因此关闭 SplashScreen 表单......)如果我错了,请纠正我......
-
线程睡眠使线程进入睡眠状态,然后线程中止可能会关闭表单,但它会不自然地这样做
-
好的,但是如果它关闭表单,为什么启动画面仍然在屏幕上......,直到:(我按键盘上的键或单击启动屏幕或其他表单),好像还在记忆中……(请参考我上传的图片)
标签: c# multithreading screen splash-screen