CriticalHandle Class

 

Represents a wrapper class for handle resources.

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


[SecurityCriticalAttribute]
[SecurityPermissionAttribute(SecurityAction::InheritanceDemand, 
	UnmanagedCode = true)]
public ref class CriticalHandle abstract : CriticalFinalizerObject, 
	IDisposable

NameDescription
System_CAPS_protmethodCriticalHandle(IntPtr)

Initializes a new instance of the CriticalHandle class with the specified invalid handle value.

NameDescription
System_CAPS_pubpropertyIsClosed

Gets a value indicating whether the handle is closed.

System_CAPS_pubpropertyIsInvalid

When overridden in a derived class, gets a value indicating whether the handle value is invalid.

NameDescription
System_CAPS_pubmethodClose()

Marks the handle for releasing and freeing resources.

System_CAPS_pubmethodDispose()

Releases all resources used by the CriticalHandle.

System_CAPS_protmethodDispose(Boolean)

Releases the unmanaged resources used by the CriticalHandle class specifying whether to perform a normal dispose operation.

System_CAPS_pubmethodEquals(Object^)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Frees all resources associated with the handle.(Overrides CriticalFinalizerObject::Finalize().)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethodReleaseHandle()

When overridden in a derived class, executes the code required to free the handle.

System_CAPS_protmethodSetHandle(IntPtr)

Sets the handle to the specified pre-existing handle.

System_CAPS_pubmethodSetHandleAsInvalid()

Marks a handle as invalid.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_protfieldhandle

Specifies the handle to be wrapped.

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.

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.

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1

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

Return to top
Show: