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

Nito.Disposables.AnonymousDisposable

Equivalent to Disposable.
public AnonymousDisposable(Action dispose)

Creates a new disposable that executes dispose when disposed.

public static AnonymousDisposable Create(Action dispose)

Creates a new disposable that executes dispose when disposed.

public void Add(Action dispose)

Adds a delegate to be executed when this instance is disposed. If this instance is already disposed or disposing, then dispose is executed immediately. If this method is called multiple times concurrently at the same time this instance is disposed, then the different dispose arguments may be disposed concurrently.