Export (0) Print
Expand All

Environment.HasShutdownStarted Property

Gets a value indicating whether the common language runtime is shutting down or the current application domain is unloading.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public static bool HasShutdownStarted { get; }
/** @property */
public static boolean get_HasShutdownStarted ()

public static function get HasShutdownStarted () : boolean

Property Value

true if the common language runtime is shutting down or the current AppDomain is unloading; otherwise, false. The current application domain is the AppDomain that contains the object that is calling HasShutdownStarted.

The finalization method for an object provides you an opportunity to perform any necessary cleanup operations before the object is garbage collected. After finalization, the object is accessible but in an invalid state and therefore unusable. Eventually, garbage collection completes and reclaims the object.

An object's finalization method is called in one of the following situations: during garbage collection, when the application domain that contains the object is unloaded, or when the common language runtime is shutting down.

While executing in your finalization method, you might want to access another object that is referenced by a static field and has a finalization method. However, you cannot reliably do so because the accessed object might already have been finalized.

NoteNote

An exception to this rule is the Console class, which contains static fields that reference stream objects, but is implemented specially so you can always write to the system console, even during domain unloading or system shutdown.

Use this method in an object's finalization method to determine whether the common language runtime is shutting down or the application domain is unloading. If that is the case, you cannot reliably access any object that has a finalization method and is referenced by a static field.

The following code example displays whether the common language runtime is shutting down.

// Sample for the Environment.HasShutdownStarted property
using System;

class Sample 
{
    public static void Main() 
    {
    Console.WriteLine();
    Console.WriteLine("HasShutdownStarted: {0}", Environment.HasShutdownStarted);
    }
}
/*
This example produces the following results:

HasShutdownStarted: False
*/

// Sample for the Environment.HasShutdownStarted property
import System.*;

class Sample
{
    public static void main(String[] args)
    {
        Console.WriteLine();
        Console.WriteLine("HasShutdownStarted: {0}", 
            System.Convert.ToString(Environment.get_HasShutdownStarted()));
    } //main
} //Sample

/*
This example produces the following results:

HasShutdownStarted: False
*/

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft