Stream.DisposeAsync Stream.DisposeAsync Stream.DisposeAsync Stream.DisposeAsync Method


异步释放 Stream 使用的非托管资源。Asynchronously releases the unmanaged resources used by the Stream.

 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


一个表示异步释放操作的任务。A task that represents the asynchronous dispose operation.



DisposeAsync方法使您能够在不阻塞主线程的情况下执行占用大量资源的释放操作。The DisposeAsync method enables you to perform a resource-intensive dispose operation without blocking the main thread. Windows 8.x 应用商店Windows 8.x Store 应用或 桌面desktop 应用中一个耗时的流操作可能阻塞 UI 线程并让您的应用看起来好像不工作时,这种性能的考虑就显得尤为重要了。This performance consideration is particularly important in a Windows 8.x 应用商店Windows 8.x Store app or 桌面desktop app where a time-consuming stream operation can block the UI thread and make your app appear as if it is not working. 结合使用异步方法asyncawaitVisual Basic 和 C# 中的关键字。The async methods are used in conjunction with the async and await keywords in Visual Basic and C#.

此方法通过写入后备存储的任何更改并关闭流,以释放资源释放流。This method disposes the stream by writing any changes to the backing store and closing the stream to release resources.

调用DisposeAsync允许使用的资源Stream重新分配用于其他目的。Calling DisposeAsync allows the resources used by the Stream to be reallocated for other purposes. 有关详细信息,请参阅清理了非托管资源For more information, see Cleaning Up Unmanaged Resources.