SafeHandle.Close SafeHandle.Close SafeHandle.Close SafeHandle.Close Method

定义

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

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

注解

通过调用Dispose或方法,可以释放资源。 CloseCalling 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.

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

备注

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

安全性

SecurityPermission
用于调用非托管代码的权限。for permission to call unmanaged code. 安全操作: LinkDemandSecurity action: LinkDemand. 关联的枚举:UnmanagedCodeAssociated enumeration: UnmanagedCode

适用于