SafeHandle.Dispose 方法

定義

釋放 SafeHandle 類別使用的資源。Releases the resources used by the SafeHandle class.

多載

Dispose()

釋放 SafeHandle 類別使用的所有資源。Releases all resources used by the SafeHandle class.

Dispose(Boolean)

釋放 SafeHandle 類別所使用的 Unmanaged 資源,指定是否要執行一般處置作業。Releases the unmanaged resources used by the SafeHandle class specifying whether to perform a normal dispose operation.

Dispose()

釋放 SafeHandle 類別使用的所有資源。Releases all resources used by the SafeHandle class.

public:
 virtual void Dispose();
public void Dispose ();
abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit
Public Sub Dispose ()

實作

備註

呼叫 CloseDispose 方法可讓資源釋放。Calling the Close or Dispose method allows the resources to be freed. 如果有其他執行緒正在使用相同的安全控制碼實例,這可能不會立即發生,但會在不再是案例之後才發生。This might not happen immediately if other threads are using the same instance of the safe handle, but will happen as soon as that is no longer the case. 雖然大部分使用 SafeHandle 的類別都不需要提供完成項,但有時候這是必要的 (例如,清除檔案緩衝區,或將一些資料寫回記憶體) 。Although most classes using SafeHandle do not need to provide a finalizer, this is sometimes necessary (for example, to flush out file buffers or to write some data back into memory). 在這種情況下,它們可以提供一個完成項,保證在執行重要的完成項之前就會執行 SafeHandleIn this case, they can provide a finalizer that is guaranteed to run before the SafeHandle critical finalizer runs.

Close Dispose 當您完成使用物件時,請呼叫或方法 SafeHandleCall the Close or Dispose method when you are finished using the SafeHandle object. Close方法會使 SafeHandle 物件處於無法使用的狀態。The Close method leaves the SafeHandle object in an unusable state.

注意

Close Dispose 在您釋放物件的最後一個參考之前,請一律呼叫或方法 SafeHandleAlways call the Close or Dispose method before you release your last reference to the SafeHandle object. 否則工作窗格所使用的資源不會釋放,直到記憶體回收行程呼叫 SafeHandle 物件的 Finalize 方法。Otherwise, the resources it is using will not be freed until the garbage collector calls the SafeHandle object's Finalize method.

Dispose(Boolean)

釋放 SafeHandle 類別所使用的 Unmanaged 資源,指定是否要執行一般處置作業。Releases the unmanaged resources used by the SafeHandle class specifying whether to perform a normal dispose operation.

protected:
 virtual void Dispose(bool disposing);
protected virtual void Dispose (bool disposing);
[System.Security.SecurityCritical]
protected virtual void Dispose (bool disposing);
abstract member Dispose : bool -> unit
override this.Dispose : bool -> unit
[<System.Security.SecurityCritical>]
abstract member Dispose : bool -> unit
override this.Dispose : bool -> unit
Protected Overridable Sub Dispose (disposing As Boolean)

參數

disposing
Boolean

true 表示一般處置作業,false 則表示結束控制代碼。true for a normal dispose operation; false to finalize the handle.

屬性

備註

您絕對不應該明確呼叫 Dispose 方法,並將 disposing 參數設為 falseYou should never explicitly call the Dispose method with the disposing parameter set to false.

適用於