所以我有一个闪屏,这将有一段时间密集的代码,我不希望它在主线程中运行。我已经做了一些应该停止线程并关闭窗体的代码,但它不起作用。欢迎任何帮助。启动画面线程
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
namespace Cobalt
{
partial class Cobalt : Form
{
public static bool splashCont { get; set; }
public Cobalt()
{
this.Text = "Cobalt V1.0.0";
this.Width = 400;
this.Height = 100;
this.BackgroundImage = Properties.Resources.cobaltlgo;
this.FormBorderStyle = FormBorderStyle.None;
this.TopMost = true;
this.StartPosition = FormStartPosition.CenterScreen;
Thread splash = new Thread(new ThreadStart(splashLoadAction));
splash.Start();
if (splashCont)
{
splash.Abort();
this.Close();
}
}
private void splashLoadAction()
{
Thread.Sleep(5000);
Cobalt.splashCont = true;
}
}
}
该计划只是停留在这个画面: Screen 编辑: 我能够通过使用下面的代码来解决这个问题:
Invoke((MethodInvoker)delegate { MyNextForm.Show(); });
它调用UI线程上的MyNextForm.Show()
。
什么是“不工作”是什么意思? – Enigmativity
另外,如果有的话你叫'Thread.Abort的()',那么你正在做的事情**非常错误的**,除非你试图强行关闭整个应用程序。 – Enigmativity