C# 应用程序中的退出方法

csharpprogrammingserver side programming更新于 2025/11/25 15:54:00

Environment.Exit() 方法

Environment.Exit() 方法终止进程并向操作系统返回退出代码 −

Environment.Exit(exitCode);

使用 exitCode 为 0(零)表示进程已成功完成。

使用 exitCode 为非零数字表示错误,例如 −

  • Environment.Exit(1) − 返回值 1 表示所需文件不存在

  • Environment.Exit(2) −返回值 2 表示文件格式不正确。

System.Windows.Forms.Application.ExitThread()

要关闭 Windows 窗体中的子应用程序或当前线程,请使用 System.Windows.Forms.Application.ExitThread()。

private void buttonClose_Click(object sender, EventArgs eventArgs) {
   System.Windows.Forms.Application.ExitThread( );
}

相关文章