Export (0) Print
Expand All

AppDomain.IsFinalizingForUnload Method

Indicates whether this application domain is unloading, and the objects it contains are being finalized by the common language runtime.

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

public bool IsFinalizingForUnload()

Return Value

Type: System.Boolean
true if this application domain is unloading and the common language runtime has started invoking finalizers; otherwise, false.

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 common language runtime is shutting down, or when the application domain that contains the object is unloaded. The IsFinalizingForUnload method returns true only in the last case; it does not return true if finalization results from routine garbage collection or from CLR shutdown.

NoteNote

To determine whether finalization is due to CLR shutdown, use the Environment.HasShutdownStarted property. It returns true if finalization is due to an application domain being unloaded or to the CLR shutting down.

While executing in your finalization method during domain unloading, 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 application domain that contains the object 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.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft