SafeHandle.Close 方法

定义

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

public:
 void Close();
public void Close ();
[System.Security.SecurityCritical]
public void Close ();
member this.Close : unit -> unit
[<System.Security.SecurityCritical>]
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.

Close使用完对象后,调用或 Dispose 方法 SafeHandleCall the Close or Dispose method when you are finished using the SafeHandle object.

备注

Close Dispose 在释放对象的最后一个引用之前,请始终调用或 SafeHandleAlways 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.

适用于