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 類別所使用的 Unmanaged 資源,指定是否要執行一般處置作業。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)

適用於

另請參閱