When should one use Environment.Exit to terminate a console application?

前端 未结 7 1359
长发绾君心
长发绾君心 2020-12-03 06:58

I\'m maintaining a number of console applications at work and one thing I\'ve been noticing in a number of them is that they call Environment.Exit(0).

A sample progr

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 07:14

    In .net core, as of right now, one must use Environment.Exit to terminate their program on Mac. Purely returning from main doesn't stop the process and it keeps running until the user aborts it. Patterns like:

    public class Program
    {
        public static void Main(string[] args)
        {
            Environment.Exit(TryRun(args));
        }
    }
    

    are common in my work place because we want to ship for both Windows and Mac.

提交回复
热议问题