gpt4 book ai didi

c# - 在 Windows 窗体中使用线程

转载 作者:行者123 更新时间:2023-11-30 21:42:52 24 4
gpt4 key购买 nike

我设计并编写了 1 个程序,它有一个用于加载的启动画面。我在主窗体中使用了线程,它将完全关闭加载窗体并显示主窗体。这个 Action 大约需要 5000 毫秒。但是当我在程序中使用线程时,在 5000 毫秒后,启动画面将消失,主窗体将正确显示。但是在主窗体显示 1 或 2 秒后,程序关闭并进入 BreakMode!不知道为什么。这是我的代码。也许我的代码有问题。预先感谢您的建议。

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 企业版)__________________________更新___________________________我用了这个方法https://stackoverflow.com/a/393870/17034并将表格名称更改为我的。但是当我再次使用我面对 BreakingMode 的程序时!这让我发疯你的建议是什么?有什么办法可以禁用此模式吗?!这是我的新代码:

using System;

使用 System.Windows.Forms;

使用 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();


}

}

最佳答案

您的程序将有一个 main.cs 启动您的 from.cs 并随后显示表单。您要做的是编辑 main.cs,以便以非异步方式显示此其他表单。然后在您的初始屏幕上使用一个计时器,该计时器在启动时启动,然后在您希望它打开的持续时间后关闭。然后 main.cs 将继续正常运行。

但是,这个答案是基于我所做的工作,可能与您的项目无关。您能否发布一个 git 链接或您的其余代码,我会更新我的答案?

关于c# - 在 Windows 窗体中使用线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42178113/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com