CriticalHandle 类

定义

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

public ref class CriticalHandle abstract : IDisposable
public ref class CriticalHandle abstract : System::Runtime::ConstrainedExecution::CriticalFinalizerObject, IDisposable
[System.Security.SecurityCritical]
public abstract class CriticalHandle : IDisposable
public abstract class CriticalHandle : System.Runtime.ConstrainedExecution.CriticalFinalizerObject, IDisposable
[System.Security.SecurityCritical]
public abstract class CriticalHandle : System.Runtime.ConstrainedExecution.CriticalFinalizerObject, IDisposable
type CriticalHandle = class
    interface IDisposable
type CriticalHandle = class
    inherit CriticalFinalizerObject
    interface IDisposable
Public MustInherit Class CriticalHandle
Implements IDisposable
Public MustInherit Class CriticalHandle
Inherits CriticalFinalizerObject
Implements IDisposable
继承
CriticalHandle
继承
派生
属性
实现

注解

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 类的新实例。Initializes a new instance of the CriticalHandle class with the specified invalid handle value.

字段

handle

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

属性

IsClosed

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

IsInvalid

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

方法

Close()

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

Dispose()

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

Dispose(Boolean)

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

Equals(Object)

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

(继承自 Object)
Finalize()

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

GetHashCode()

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

(继承自 Object)
GetType()

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

(继承自 Object)
MemberwiseClone()

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

(继承自 Object)
ReleaseHandle()

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

SetHandle(IntPtr)

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

SetHandleAsInvalid()

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

ToString()

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

(继承自 Object)

适用于

另请参阅