DbDataReader.DisposeAsync 方法


异步释放 DbDataReader 类的当前实例所使用的所有资源。Asynchronously releases all resources used by the current instance of the DbDataReader class.

 virtual System::Threading::Tasks::ValueTask DisposeAsync();
public virtual System.Threading.Tasks.ValueTask DisposeAsync ();
abstract member DisposeAsync : unit -> System.Threading.Tasks.ValueTask
override this.DisposeAsync : unit -> System.Threading.Tasks.ValueTask
Public Overridable Function DisposeAsync () As ValueTask



表示异步操作的 ValueTaskA ValueTask representing the asynchronous operation.



使用完成后,调用 DisposeDisposeAsync DbDataReaderCall Dispose or DisposeAsync when you've finished using the DbDataReader. 调用这些方法之一会使 DbDataReader 处于不可用状态。Calling one of these methods leaves the DbDataReader in an unusable state. 释放后,必须释放对的所有引用, DbDataReader 这样垃圾回收器才能收回占用的内存 DbDataReaderAfter disposing, you must release all references to the DbDataReader so the garbage collector can reclaim the memory that the DbDataReader was occupying.

有关详细信息,请参阅 清理非托管资源实现 Dispose 方法For more information, see Cleaning Up Unmanaged Resources and Implementing a Dispose Method.


在释放对的最后一个引用之前,始终释放 DbDataReaderAlways dispose before you release your last reference to the DbDataReader. 否则,在垃圾回收器调用 DbDataReader 对象的 Finalize 方法之前,该对象正在使用的资源不会被释放。Otherwise, the resources it is using will not be freed until the garbage collector calls the DbDataReader object's Finalize method.

此异步方法的默认实现将委托给其同步对应项,并返回已完成的 ValueTask ,这可能会阻止调用线程。The default implementation of this asynchronous method delegates to its synchronous counterpart and returns a completed ValueTask, potentially blocking the calling thread.

支持 异步编程 的数据访问接口应使用异步 i/o 操作来重写默认实现。Data providers that support asynchronous programming should override the default implementation using asynchronous I/O operations.