CriticalHandle CriticalHandle CriticalHandle CriticalHandle Class


表示句柄资源的包装类。Represents a wrapper class for handle resources.

public ref class CriticalHandle abstract : System::Runtime::ConstrainedExecution::CriticalFinalizerObject, IDisposable
public abstract class CriticalHandle : System.Runtime.ConstrainedExecution.CriticalFinalizerObject, IDisposable
type CriticalHandle = class
    inherit CriticalFinalizerObject
    interface IDisposable
Public MustInherit Class CriticalHandle
Inherits CriticalFinalizerObject
Implements IDisposable


CriticalHandle类是类似于SafeHandle类,不同之处在于SafeHandle实现引用计数。The CriticalHandle class is similar to the SafeHandle class, except that SafeHandle implements reference counting. 可以使用CriticalHandle而不是SafeHandle来解决性能问题的详细信息提供必要的同步时有效地自己。You can use CriticalHandle instead of SafeHandle to address performance considerations when you can provide the necessary synchronization more efficiently yourself.

因为CriticalHandle类不会执行引用计数,它不提供从句柄回收安全攻击的保护。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. 如果您调用IDisposable.DisposeClose方法而不是另一个线程上完成的操作是使用该句柄,或如果调用IDisposable.DisposeClose同时在两个线程,从结果是不确定。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. CriticalHandle类仍提供有保证的关键终止CriticalFinalizerObject类。The CriticalHandle class still provides the guaranteed critical finalization provided by the CriticalFinalizerObject class.


CriticalHandle(IntPtr) CriticalHandle(IntPtr) CriticalHandle(IntPtr) CriticalHandle(IntPtr)

用指定的无效句柄值初始化 CriticalHandle 类的新实例。Initializes a new instance of the CriticalHandle class with the specified invalid handle value.


handle handle handle handle

指定要包装的句柄。Specifies the handle to be wrapped.


IsClosed IsClosed IsClosed IsClosed

获取一个值,该值指示句柄是否已关闭。Gets a value indicating whether the handle is closed.

IsInvalid IsInvalid IsInvalid IsInvalid

在派生类中重写后,获取一个值,该值指示句柄值是否无效。When overridden in a derived class, gets a value indicating whether the handle value is invalid.


Close() Close() Close() Close()

标记句柄,以便释放资源。Marks the handle for releasing and freeing resources.

Dispose() Dispose() Dispose() Dispose()

释放由 CriticalHandle 使用的所有资源。Releases all resources used by the CriticalHandle.

Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

释放 CriticalHandle 类所使用的非托管资源,并指定是否执行常规释放 (Dispose) 操作。Releases the unmanaged resources used by the CriticalHandle class specifying whether to perform a normal dispose operation.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize() Finalize() Finalize() Finalize()

释放与句柄关联的所有资源。Frees all resources associated with the handle.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
ReleaseHandle() ReleaseHandle() ReleaseHandle() ReleaseHandle()

如果在派生类中重写,执行释放句柄所需的代码。When overridden in a derived class, executes the code required to free the handle.

SetHandle(IntPtr) SetHandle(IntPtr) SetHandle(IntPtr) SetHandle(IntPtr)

将句柄设置为预先存在的指定句柄。Sets the handle to the specified pre-existing handle.

SetHandleAsInvalid() SetHandleAsInvalid() SetHandleAsInvalid() SetHandleAsInvalid()

将句柄标记为无效。Marks a handle as invalid.

ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)


继承者完全信任。for full trust for inheritors. 此成员不能由部分受信任代码继承。This member cannot be inherited by partially trusted code.

直接调用方需要完全信任。requires full trust for the immediate caller. 部分受信任的或透明代码不能使用此类。This class cannot be used by partially trusted or transparent code.