Environment.Exit和简单的回报2的主要区别 [英] Difference between Environment.Exit and simple return 2 from Main

查看:117
本文介绍了Environment.Exit和简单的回报2的主要区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从应用程序之外,是否有

From outside of the application, is there any difference between

...
Environment.Exit(2)

static int Main()
{
    ...
    return 2;
}

推荐答案

最明显的区别是,你可以从你的code的任何地方拨打Environment.Exit。除此之外:

The most obvious difference is that you can call Environment.Exit from anywhere in your code. Aside from that:

  • 主要整理不会终止该进程是否有执行的其他前台线程; Environment.Exit 将取下来的过程呢。
  • Environment.Exit 终止进程的没有的展开堆栈和(根据我的实验至少)执行finally块。显然,当你从主返回您已经在顶级至于管理code是担心。
  • 在两个给终结过程中的真正的关闭
  • 之前执行的机会
  • Environment.Exit 要求适当的安全权限,这样就不会少受信任的应用程序的工作。
  • Main finishing won't terminate the process if there are other foreground threads executing; Environment.Exit will take down the process anyway.
  • Environment.Exit terminates the process without unwinding the stack and executing finally blocks (at least according to my experiments). Obviously when you return from Main you're already at the top level as far as managed code is concerned.
  • Both give finalizers a chance to execute before the process really shuts down
  • Environment.Exit demands the appropriate security permission, so won't work for less trusted apps.

在看到问题的更新,我不完全明白你的意思。在这两种情况下,这个过程只会退出以2 code ...

Having seen the question update, I'm not entirely sure what you mean. In both cases the process will just exit with a code of 2...

这篇关于Environment.Exit和简单的回报2的主要区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆