gpt4 book ai didi

c# - 线程仍在 C# 中运行

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

我有 2 个表单:signincontrol_panel。登录完成后,我通过 this.Hide() 函数隐藏此表单,同时我正在创建 control_panel 表单的新对象并通过 newobj 显示它。显示();。但是当我直接关闭 control_panel 表单时,我看到第一个表单线程仍在运行。我通过 stop_debugging 按钮关闭它。我将如何关闭每个线程或整个程序同时退出。

最佳答案

第一个表单的线程仍在运行,因为您只调用了 this.Hide . 所做的只是隐藏表单;它不会关闭它。相反,您需要使用 this.Close ,这将关闭您的原始表单。

如果你想确保你的整个应用程序退出,并在这个过程中关闭任何可能仍然打开的表单,你可以使用 Application.Exit表单代码中任意位置的方法。


编辑:为了扩展我最后的评论,您可能希望在您的 Program.cs 文件中有这样的内容:

static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

SignInForm frmSignIn = new SignInForm();
if (frmSignIn.ShowDialog() == DialogResult.Yes)
{
//If the sign-in completed successfully, show the main form
//(otherwise, the application will quit because the sign-in failed)
Application.Run(new ControlPanelForm());
}
}
}

关于c# - 线程仍在 C# 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4275992/

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