CriticalHandle 类

定义

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

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

注解

类与SafeHandle类相似, 不同之处在于SafeHandle实现引用计数。 CriticalHandleThe 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.Dispose线程Close上未完成使用该句柄的操作时调用或方法, 或者如果同时从两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. 类仍提供CriticalFinalizerObject由类提供的有保证的关键终结。 CriticalHandleThe 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 类所使用的非托管资源,并指定是否执行常规释放 (Dispose) 操作。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)

安全性

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.

适用于

另请参阅