<PackageReference Include="Nito.Disposables" Version="2.4.0" />

Nito.Disposables.ReferenceCountedAsyncDisposable

public static class ReferenceCountedAsyncDisposable
Creation methods for reference counted disposables.
public static IReferenceCountedAsyncDisposable<T> Create<T>(T disposable) where T : IAsyncDisposable

Creates a new disposable that disposes disposable when all reference counts have been disposed. This method uses attached (ephemeron) reference counters.

Creates a new disposable that disposes disposable when all reference counts have been disposed. This method creates a new reference counter to keep track of the reference counts.

public static IReferenceCountedAsyncDisposable<T> TryCreate<T>(T disposable) where T : IAsyncDisposable

Creates a new disposable that disposes disposable when all reference counts have been disposed. This method uses attached (ephemeron) reference counters.