所以我有一個閃屏,這將有一段時間密集的代碼,我不希望它在主線程中運行。我已經做了一些應該停止線程並關閉窗體的代碼,但它不起作用。歡迎任何幫助。啓動畫面線程
代碼:
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