Description
Type of issue
Typo
Description
• Dispose(bool disposing) is called with true when the object is being disposed explicitly (by user code), and with false when called from a finalizer (to clean up unmanaged resources only).
• In the async dispose pattern, DisposeAsync() should call DisposeAsyncCore() to asynchronously release resources, then suppress finalization.
• There is no need to call Dispose(false) from DisposeAsync(), because:
• You are not in a finalizer.
• All resource cleanup should already be handled in DisposeAsyncCore().
The correct pattern for IAsyncDisposable is:
public async ValueTask DisposeAsync() { await DisposeAsyncCore().ConfigureAwait(false); GC.SuppressFinalize(this); }
Page URL
https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-disposeasync
Content source URL
Document Version Independent Id
d72276e1-9059-815f-dc14-a03a7544ab87
Platform Id
cc69165e-7f9b-8c59-0b79-2ba09c791e8e
Article author
Metadata
- ID: 61a961dc-3ebf-2a96-a6eb-2e0b62ab909f
- PlatformId: cc69165e-7f9b-8c59-0b79-2ba09c791e8e
- Service: dotnet-fundamentals