Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

CriticalHandle Class

Represents a wrapper class for handle resources.

Namespace:  System.Runtime.InteropServices
Assembly:  mscorlib (in mscorlib.dll)
[SecurityPermissionAttribute(SecurityAction.InheritanceDemand, UnmanagedCode = true)]
public abstract class CriticalHandle : CriticalFinalizerObject, 
	IDisposable

The CriticalHandle type exposes the following members.

  NameDescription
Protected methodCriticalHandleInitializes a new instance of the CriticalHandle class with the specified invalid handle value.
Top
  NameDescription
Public propertyIsClosedGets a value indicating whether the handle is closed.
Public propertyIsInvalidWhen overridden in a derived class, gets a value indicating whether the handle value is invalid.
Top
  NameDescription
Public methodCloseMarks the handle for releasing and freeing resources.
Public methodDispose()Releases all resources used by the CriticalHandle.
Protected methodDispose(Boolean)Releases the unmanaged resources used by the CriticalHandle class specifying whether to perform a normal dispose operation.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeFrees all resources associated with the handle. (Overrides CriticalFinalizerObject.Finalize().)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodReleaseHandleWhen overridden in a derived class, executes the code required to free the handle.
Protected methodSetHandleSets the handle to the specified pre-existing handle.
Public methodSetHandleAsInvalidMarks a handle as invalid.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top
  NameDescription
Protected fieldhandleSpecifies the handle to be wrapped.
Top

The CriticalHandle class is similar to the SafeHandle class, except that SafeHandle implements reference counting. You can use CriticalHandle instead of SafeHandle to address performance considerations when you can provide the necessary synchronization more efficiently yourself.

Because the CriticalHandle class does not perform reference counting, it does not provide protection from handle recycling security attacks. Because the reference counting algorithm implicitly serializes operations, a certain amount of thread safety is also lost. If you call the IDisposable.Dispose or Close method while an operation that is using the handle is outstanding on another thread, or if you call IDisposable.Dispose or Close from two threads at the same time, the results are non-deterministic. The CriticalHandle class still provides the guaranteed critical finalization provided by the CriticalFinalizerObject class.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
  • InheritanceDemand 

    for full trust for inheritors. This member cannot be inherited by partially trusted code.

  • SecurityCriticalAttribute 

    requires full trust for the immediate caller. This class cannot be used by partially trusted or transparent code.

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.