Skip to content

Add the NoopAsyncDisposable code for context #32805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Implement a DisposeAsync method
description: Learn how to implement DisposeAsync and DisposeAsyncCore methods to perform asynchronous resource cleanup.
author: IEvangelist
ms.author: dapine
ms.date: 10/26/2022
ms.date: 11/30/2022
dev_langs:
- "csharp"
helpviewer_keywords:
Expand Down Expand Up @@ -68,7 +68,11 @@ The `DisposeAsyncCore()` method is intended to perform the asynchronous cleanup

## Implement the async dispose pattern

All non-sealed classes should be considered a potential base class, because they could be inherited. If you implement the async dispose pattern for any potential base class, you must provide the `protected virtual ValueTask DisposeAsyncCore()` method. Here is an example implementation of the async dispose pattern that using a custom `NoopAsyncDisposable` type that implements `DisposeAsync` by returning <xref:System.Threading.Tasks.ValueTask.CompletedTask?displayProperty=nameWithType>.
All non-sealed classes should be considered a potential base class, because they could be inherited. If you implement the async dispose pattern for any potential base class, you must provide the `protected virtual ValueTask DisposeAsyncCore()` method. Some of the following examples use a `NoopAsyncDisposable` class that is defined as follows:

:::code language="csharp" source="snippets/dispose-async/NoopAsyncDisposable.cs":::

Here is an example implementation of the async dispose pattern that using a custom `NoopAsyncDisposable` type that implements `DisposeAsync` by returning <xref:System.Threading.Tasks.ValueTask.CompletedTask?displayProperty=nameWithType>.

:::code language="csharp" source="snippets/dispose-async/ExampleAsyncDisposable.cs":::

Expand Down