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

Nito.Disposables.Disposable

public sealed class Disposable : SingleDisposable<Action>
A disposable that executes a delegate when disposed.
public Disposable(Action dispose)

Creates a new disposable that executes dispose when disposed.

public static Disposable 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.