且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何正确退出/停止/处置C#中的控制台应用程序

更新时间:2023-02-19 17:55:35

控制台应用程序完成后通常会终止,通常是运行到其 Main 入口点方法的末尾,尽管您必须小心摆脱任何挥之不去的资源您可能一直在进行管理,因为它们可以使基础流程保持活动状态。

A console application will just terminate when it's done, generally when it runs to the end of its Main entry point method, though you must be careful to get rid of any lingering resources you might have been managing, as they can keep the underlying process alive.

您可以使用 Environment.Exit 明确退出。 >,以及 Application.Exit ,尽管后者根据我的经验是基于表单的(与清除消息泵和关闭窗口等有关)。

You can explicitly exit using Environment.Exit, and also Application.Exit although the latter is Forms-based from my experience (relating to clearing message pumps and closing windows etc.).

最重要的是确保做家务。

Bottom line is to be sure to do housekeeping.