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

来源:这里教程网 时间:2026-02-21 16:19:48 作者:

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

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( );
}

相关推荐