如果不是 IsDefaultAppDomain,则从任何 AppDomain 调用的 Environment.Exit 是否会退出整个过程? [英] Does Environment.Exit called from any AppDomain exit the entire process if not IsDefaultAppDomain?

查看:23
本文介绍了如果不是 IsDefaultAppDomain,则从任何 AppDomain 调用的 Environment.Exit 是否会退出整个过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最初对 Environment.Exit 的看法是这样的:

My original belief about Environment.Exit was this:

  1. 如果从默认的 AppDomain 调用,该进程将终止.

  1. If called from the default AppDomain, the process would terminate.

如果从非默认的 AppDomain 调用,AppDomain 将终止并将退出代码推送到 AppDomain.ExecuteAssembly 的返回中.

If called from an AppDomain other than default, the AppDomain would terminate and push the exit code into the return of AppDomain.ExecuteAssembly.

这对我来说似乎是合乎逻辑的,因为加载的 AppDomain 由于调用 Environment.Exit 而不是像 https://stackoverflow.com/questions/3971101/c-sharp-whats-The-best-way-to-end-a-program 谈到.

This seemed logical to me, as it would forseeably be undesirable for a loaded AppDomain to unintentionally kill the entire process due to calling Environment.Exit instead of ending at the "}" like the accepted answer of https://stackoverflow.com/questions/3971101/c-sharp-whats-the-best-way-to-end-a-program speaks of.

但是MSDN 描述如下:

However the MSDN description of Environment.Exit is as follows:

终止此进程并为底层操作系统提供指定的退出代码.

Terminates this process and gives the underlying operating system the specified exit code.

所以这让我想知道,Environment.Exit 是否会像 MSDN 所说的那样杀死整个进程,或者它是否像我最初的假设那样工作?

So this makes me wonder, does Environment.Exit kill the entire process as the MSDN says, or does it work like my original assumption?

推荐答案

MSDN 库文章当然是准确的.不,你不能只是调用 Environment.Exit() 并希望它能够工作,它有一个 CAS 需求.一个高大的,必须信任代码才能运行危险代码,SecurityPermissionFlag.UnmanagedCode.您通常只能完全信任它.

The MSDN library article is accurate of course. And no, you cannot just call Environment.Exit() and hope it will work, it has a CAS demand. A tall one, the code must be trusted to run dangerous code, SecurityPermissionFlag.UnmanagedCode. You normally only get that in full trust.

AppDomain 中的沙盒代码非常简单,此 MSDN 页面展示如何.

Sandboxing code in an AppDomain is pretty easy, this MSDN page shows how.

这篇关于如果不是 IsDefaultAppDomain,则从任何 AppDomain 调用的 Environment.Exit 是否会退出整个过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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