From 8c6bceb7132c57022ae911d1f4e1e287ebca6e66 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 6 Jan 2026 01:22:57 +0000 Subject: [PATCH 1/2] Initial plan From 12f01f8ae25c7c659717af15a2d0d000cf0b8a72 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 6 Jan 2026 01:28:01 +0000 Subject: [PATCH 2/2] Fix DisposeAsync pattern: remove incorrect Dispose(false) call Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com> --- .../garbage-collection/implementing-disposeasync.md | 8 +------- .../dispose-async/ExampleConjunctiveDisposable.cs | 1 - 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/docs/standard/garbage-collection/implementing-disposeasync.md b/docs/standard/garbage-collection/implementing-disposeasync.md index d750de5cf2a98..c309de1f2b1e2 100644 --- a/docs/standard/garbage-collection/implementing-disposeasync.md +++ b/docs/standard/garbage-collection/implementing-disposeasync.md @@ -42,19 +42,13 @@ The `public` parameterless `DisposeAsync()` method is called implicitly in an `a public async ValueTask DisposeAsync() { // Perform async cleanup. - await DisposeAsyncCore(); - - // Dispose of unmanaged resources. - Dispose(false); + await DisposeAsyncCore().ConfigureAwait(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 0dfbe02bf1966..2a7966849a697 100644 --- a/docs/standard/garbage-collection/snippets/dispose-async/ExampleConjunctiveDisposable.cs +++ b/docs/standard/garbage-collection/snippets/dispose-async/ExampleConjunctiveDisposable.cs @@ -13,7 +13,6 @@ public async ValueTask DisposeAsync() { await DisposeAsyncCore().ConfigureAwait(false); - Dispose(disposing: false); GC.SuppressFinalize(this); }