<PackageReference Include="Nito.Disposables" Version="2.2.0-pre01" />

Nito.Disposables.ReferenceCountedDisposable

public sealed class ReferenceCountedDisposable : IDisposable
A reference-counted wrapper for a disposable. The wrapper itself is the first reference. Once all references are disposed, the underlying disposable is disposed. All future reference disposals are no-ops.
public bool IsDisposed { get; }

Whether the wrapped disposable is disposed (finished disposing).

public bool IsDisposeStarted { get; }

Whether the wrapped disposable is currently disposing or has been disposed.

public bool IsDisposing { get; }

Whether the wrapped disposable is currently disposing, but not finished yet.

Creates a reference-counted wrapper for the specified disposable.

Increments the reference count and returns a disposable that decrements the reference count when disposed. The returned disposable may be disposed multiple times; it will only decrement the reference count once.

public void Dispose()

Frees the reference count held by this wrapper instance.