Export (0) Print
Expand All

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 methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsCriticalHandleInitializes a new instance of the CriticalHandle class with the specified invalid handle value.
Top

  NameDescription
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsIsClosedGets a value indicating whether the handle is closed.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsIsInvalidWhen 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 LibrarySupported in .NET for Windows Store appsDispose()Releases all resources used by the CriticalHandle.
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsDispose(Boolean)Releases the unmanaged resources used by the CriticalHandle class specifying whether to perform a normal dispose operation.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsFinalizeFrees all resources associated with the handle. (Overrides CriticalFinalizerObject.Finalize().)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsReleaseHandleWhen overridden in a derived class, executes the code required to free the handle.
Protected methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsSetHandleSets the handle to the specified pre-existing handle.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsSetHandleAsInvalidMarks a handle as invalid.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Protected fieldSupported by Portable Class LibrarySupported in .NET for Windows Store appshandleSpecifies 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.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

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

  • 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 Phone 8.1, Windows Phone 8, 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.

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:
© 2014 Microsoft