SafeHandle.Close 方法

定義

標記要釋出和釋放資源的控制代碼。Marks the handle for releasing and freeing resources.

public:
 void Close();
[System.Security.SecurityCritical]
public void Close ();
public void Close ();
member this.Close : unit -> unit
Public Sub Close ()
屬性

備註

呼叫 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 safe handle object, but will happen as soon as that is no longer the case. 雖然大部分使用 SafeHandle 類別的類別都不需要提供完成項,但有時也需要這麼做(例如,清除檔案緩衝區,或將一些資料寫回記憶體中)。Although most classes that use the SafeHandle class 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). 在此情況下,類別可以提供在 SafeHandle 重要完成項執行之前保證執行的完成項。In this case, the class can provide a finalizer that is guaranteed to run before the SafeHandle critical finalizer runs.

當您完成使用 SafeHandle 物件時,請呼叫 CloseDispose 方法。Call the Close or Dispose method when you are finished using the SafeHandle object.

注意

在您釋放 SafeHandle 物件的最後一個參考之前,請一律呼叫 CloseDisposeAlways call Close or Dispose 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.

適用於