diff --git a/docs/standard/garbage-collection/implementing-disposeasync.md b/docs/standard/garbage-collection/implementing-disposeasync.md index c309de1f2b1e2..3af8e8524b161 100644 --- a/docs/standard/garbage-collection/implementing-disposeasync.md +++ b/docs/standard/garbage-collection/implementing-disposeasync.md @@ -44,11 +44,17 @@ public async ValueTask DisposeAsync() // Perform async cleanup. await DisposeAsyncCore().ConfigureAwait(false); + // Dispose of unmanaged resources. + Dispose(false); + // Suppress finalization. GC.SuppressFinalize(this); } ``` +> [!NOTE] +> One primary difference in the async dispose pattern compared to the dispose pattern, is that the call from to the `Dispose(bool)` overload method is given `false` as an argument. When implementing the method, however, `true` is passed instead. This helps ensure functional equivalence with the synchronous dispose pattern, and further ensures that finalizer code paths still get invoked. In other words, the `DisposeAsyncCore()` method will dispose of managed resources asynchronously, so you don't want to dispose of them synchronously as well. Therefore, call `Dispose(false)` instead of `Dispose(true)`. + ### The `DisposeAsyncCore` method The `DisposeAsyncCore()` method is intended to perform the asynchronous cleanup of managed resources or for cascading calls to `DisposeAsync()`. It encapsulates the common asynchronous cleanup operations when a subclass inherits a base class that is an implementation of . The `DisposeAsyncCore()` method is `virtual` so that derived classes can define custom cleanup in their overrides. diff --git a/docs/standard/garbage-collection/snippets/dispose-async/ExampleConjunctiveDisposable.cs b/docs/standard/garbage-collection/snippets/dispose-async/ExampleConjunctiveDisposable.cs index 2a7966849a697..0dfbe02bf1966 100644 --- a/docs/standard/garbage-collection/snippets/dispose-async/ExampleConjunctiveDisposable.cs +++ b/docs/standard/garbage-collection/snippets/dispose-async/ExampleConjunctiveDisposable.cs @@ -13,6 +13,7 @@ public async ValueTask DisposeAsync() { await DisposeAsyncCore().ConfigureAwait(false); + Dispose(disposing: false); GC.SuppressFinalize(this); }