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

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 Action Abandon()

Makes this disposable do nothing when it is disposed. Returns the actions this disposable *would* have taken; these can be passed to a new instance to transfer ownership.

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.