【发布时间】:2014-01-02 20:51:19
【问题描述】:
Form1.cs
public Form1()
{
Thread SplashThread = new Thread(new ThreadStart(SplashScreen));
SplashThread.Start();
Thread.Sleep(5000);
SplashThread.Abort();
InitializeComponent();
this.BringToFront();
PlayerOne[1] = new BladeWarrior();
PlayerOne[2] = new FistWarrior();
PlayerOne[3] = new Archer();
PlayerOne[4] = new RedMage();
PlayerOne[5] = new BlueMage();
}
public void SplashScreen()
{
Application.Run(new SplashScreen());
}
SplashScreen.cs
public SplashScreen()
{
InitializeComponent();
LoadGearFiles LoadGear = new LoadGearFiles();
LoadGear.StartPatching(this);
}
Timer t = new Timer();
void t_Tick(object sender, EventArgs e)
{
if (LoadingBar.Value == 100) t.Stop();
}
加载齿轮文件.cs
public void StartPatching(SplashScreen Splash)
{
Splash.PatchingLabel.Text = "Patching in progress! This may take a moment or two!";
Thread.Sleep(SleepTime);
Splash.LoadingBar.Value += 25;
LoadWeapons(Splash);
Splash.LoadingBar.Value += 25;
LoadArmor(Splash);
Splash.LoadingBar.Value += 25;
LoadRings(Splash);
Splash.LoadingBar.Value += 25;
Splash.PatchingLabel.Text = "Patch Complete!";
}
我的问题是我的启动画面显示但基于 Thread.Sleep(5000) 而关闭,而不是进度条值等于其最大值。如果我注释掉 Thread.Sleep(5000) 启动画面几乎会立即关闭。在 LoadGearFiles 类中,没有什么特别的,它只是流式读取器/写入器读取和写入记事本文件,将信息加载到数组中。他们成功读/写/填充。此外,在加载齿轮文件类中,我会在读取或写入某些文件后增加进度条的值。我的问题似乎在这里。我应该采取什么样的逻辑/句法方法?
【问题讨论】:
-
如果您删除您的
SplashThread.Abort();电话会怎样?或者更直接地说,你为什么要打那个Abort()? -
您使用的是什么版本的 C#? 4.0+ 有更简单的方法来处理这样的线程情况。
-
如果我注释掉 SplashThread.Abort();启动画面根本不会关闭。将弹出另一个表单,并且启动画面将留在后台。 @ledbutter 如何检查我使用的是哪个版本?
-
右键单击您的项目,选择“属性”,在“应用程序”选项卡上有一个“目标框架”组合框,其中显示的值是您正在使用的 C# 版本。
标签: c# multithreading splash-screen