Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

Environment.HasShutdownStarted Property

Indicates whether the common language runtime is shutting down or the current application domain is unloading.

[Visual Basic]
Public Shared ReadOnly Property HasShutdownStarted As Boolean
[C#]
public static bool HasShutdownStarted {get;}
[C++]
public: __property static bool get_HasShutdownStarted();
[JScript]
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.

Remarks

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.

Note   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.

Example

[Visual Basic] 
' Sample for the Environment.HasShutdownStarted property
Imports System

Class Sample
   Public Shared Sub Main()
      Console.WriteLine()
      Console.WriteLine("HasShutdownStarted: {0}", Environment.HasShutdownStarted)
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'HasShutdownStarted: False
'

[C#] 
// 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
*/

[C++] 
// Sample for the Environment::HasShutdownStarted property
#using <mscorlib.dll>

using namespace System;

int main() {
   Console::WriteLine();
   Console::WriteLine(S"HasShutdownStarted: {0}", __box(Environment::HasShutdownStarted));
}
/*
This example produces the following results:

HasShutdownStarted: False
*/

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

Environment Class | Environment Members | System Namespace | AppDomain.IsFinalizingForUnload

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.