Environment.HasShutdownStarted 属性
定义
获取一个值,该值指示当前的应用程序域是否正在卸载或者公共语言运行时 (CLR) 是否正在关闭。Gets a value that indicates whether the current application domain is being unloaded or the common language runtime (CLR) is shutting down.
public:
static property bool HasShutdownStarted { bool get(); };
public static bool HasShutdownStarted { get; }
member this.HasShutdownStarted : bool
Public Shared ReadOnly Property HasShutdownStarted As Boolean
属性值
true 如果当前的应用程序域正在卸载或者 CLR 正在关闭,则为;否则为 false 。true if the current application domain is being unloaded or the CLR is shutting down; otherwise, false.
注解
仅 .NET Framework:当 CLR 卸载应用程序域时,它将对在该应用程序域中具有终结器方法的所有对象运行终结器。.NET Framework only: When the CLR unloads an application domain, it runs the finalizers on all objects that have a finalizer method in that application domain. CLR 关闭时,它将在具有终结器方法的所有对象上启动终结器线程。When the CLR shuts down, it starts the finalizer thread on all objects that have a finalizer method. HasShutdownStarted属性仅在 true 终结器线程启动后返回。The HasShutdownStarted property returns true only after the finalizer thread has been started. 当属性返回时 true ,可以通过调用方法来确定应用程序域是否正在卸载或者 CLR 本身是否正在关闭 AppDomain.IsFinalizingForUnload 。When the property returns true, you can determine whether an application domain is being unloaded or the CLR itself is shutting down by calling the AppDomain.IsFinalizingForUnload method. true如果因为应用程序域正在卸载或者 CLR 正在关闭而调用终结器,则此方法返回 false 。This method returns true if finalizers are called because the application domain is unloading or false if the CLR is shutting down.
HasShutdownStarted false 如果终结器线程尚未启动,则属性将返回。The HasShutdownStarted property returns false if the finalizer thread has not been started.
通过使用此属性,您可以确定是否在终止代码中访问静态变量。By using this property, you can determine whether to access static variables in your finalization code. 如果应用程序域或 CLR 正在关闭,则无法可靠地访问包含终止方法并且由静态字段引用的任何对象。If either an application domain or the CLR is shutting down, you cannot reliably access any object that has a finalization method and that is referenced by a static field. 这是因为这些对象可能已经完成了。This is because these objects may have already been finalized.