System.Runtime.InteropServices.CriticalHandle Class

Represents a wrapper class for handle resources.

See Also: CriticalHandle Members

Syntax

public abstract class CriticalHandle : System.Runtime.ConstrainedExecution.CriticalFinalizerObject, IDisposable

Remarks

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

Because the System.Runtime.InteropServices.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 SafeHandle.Close method while an operation that is using the handle is outstanding on another thread, or if you call IDisposable.Dispose or SafeHandle.Close from two threads at the same time, the results are non-deterministic. The System.Runtime.InteropServices.CriticalHandle class still provides the guaranteed critical finalization provided by the System.Runtime.ConstrainedExecution.CriticalFinalizerObject class.

Requirements

Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0