Sdílet prostřednictvím


CriticalFinalizerObject Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Ensures that all finalization code in derived classes is marked as critical.

Inheritance Hierarchy

System.Object
  System.Runtime.ConstrainedExecution.CriticalFinalizerObject
    System.Runtime.InteropServices.CriticalHandle
    System.Runtime.InteropServices.SafeHandle
    System.Threading.Thread

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

Syntax

'Declaration
<ComVisibleAttribute(True)> _
Public MustInherit Class CriticalFinalizerObject
[ComVisibleAttribute(true)]
public abstract class CriticalFinalizerObject

The CriticalFinalizerObject type exposes the following members.

Constructors

  Name Description
Protected method CriticalFinalizerObject Initializes a new instance of the CriticalFinalizerObject class.

Top

Methods

  Name Description
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Releases all the resources used by the CriticalFinalizerObject class. (Overrides Object.Finalize().)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

Classes that are derived from the CriticalFinalizerObject class are implicitly treated as a constrained execution region (CER). This requires code in the finalizer to only call code with a strong reliability contract. For more information about CERs, see the System.Runtime.ConstrainedExecution namespace.

NoteNote:

In a Silverlight-based application, you cannot inherit from the CriticalFinalizerObject class.

In classes that are derived from the CriticalFinalizerObject class, the common language runtime (CLR) guarantees that all critical finalization code will be given the opportunity to execute, provided the finalizer follows the rules for a CER, even when the CLR forcibly unloads an application domain or ends a thread. If a finalizer violates the rules for a CER, it might not successfully execute. In addition, the CLR establishes a weak ordering among normal and critical finalizers: For objects that are reclaimed by garbage collection at the same time, all the noncritical finalizers are called before any of the critical finalizers. For example, a class such as FileStream, which holds data in the SafeHandle class that is derived from CriticalFinalizerObject, can run a standard finalizer to flush out existing buffered data.

In most cases, you do not have to write classes that derive from the CriticalFinalizerObject class. The .NET Framework class library provides two classes, SafeHandle and CriticalHandle, that provide critical finalization functionality for handle resources. Furthermore, the .NET Framework provides a set of prewritten classes derived from the SafeHandle class, and this set is located in the Microsoft.Win32.SafeHandles namespace. These classes are designed to provide common functionality for supporting file and operating system handles.

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.