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

查看:128
本文介绍了如果不是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而不是像已接受的

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天全站免登陆