Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

CriticalHandle Class

Represents a wrapper class for handle resources.

System.Object
  System.Runtime.InteropServices.CriticalHandle

Namespace:  System.Runtime.InteropServices
Assemblies:   System.Runtime.Handles (in System.Runtime.Handles.dll)
  mscorlib (in mscorlib.dll)

public abstract class CriticalHandle : IDisposable

The CriticalHandle type exposes the following members.

  NameDescription
Protected methodSupported by Portable Class LibraryCriticalHandleInitializes a new instance of the CriticalHandle class with the specified invalid handle value.
Top

  NameDescription
Public propertySupported by Portable Class LibraryIsClosedGets a value indicating whether the handle is closed.
Public propertySupported by Portable Class LibraryIsInvalidWhen 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 methodSupported by Portable Class LibraryDispose()Releases all resources used by the CriticalHandle.
Protected methodSupported by Portable Class LibraryDispose(Boolean)Releases the unmanaged resources used by the CriticalHandle class specifying whether to perform a normal dispose operation.
Public methodSupported by Portable Class LibraryEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported by Portable Class LibraryFinalizeFrees all resources associated with the handle. (Overrides Object.Finalize().)
Public methodSupported by Portable Class LibraryGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported by Portable Class LibraryGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Portable Class LibraryMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodSupported by Portable Class LibraryReleaseHandleWhen overridden in a derived class, executes the code required to free the handle.
Protected methodSupported by Portable Class LibrarySetHandleSets the handle to the specified pre-existing handle.
Public methodSupported by Portable Class LibrarySetHandleAsInvalidMarks a handle as invalid.
Public methodSupported by Portable Class LibraryToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Protected fieldSupported by Portable Class LibraryhandleSpecifies 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.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library

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

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