DotNext by .NET Foundation and Contributors

<PackageReference Include="DotNext" Version="4.8.1" />

 GCNotification

public abstract class GCNotification
Provides a way to receive notifications from Garbage Collector asynchronously.
public struct Registration : IDisposable

Represents callback registration.

public static GCNotification GCTriggered()

Creates a filter that triggers notification on every GC occurred.

public static GCNotification GCTriggered(int generation)

Creates a filter that allows to detect garbage collection of the specified generation.

Creates a filter that allows to detect heap compaction.

public static GCNotification HeapFragmentation(double threshold)

Creates a filter that allows to detect managed heap fragmentation threshold.

public static GCNotification MemoryThreshold(double threshold)

Creates a filter that allows to detect managed heap occupation.

Combines two filters using logical AND.

Combines two filters using logical OR.

Combines two filters using logical XOR.

Negates the filter.

public virtual GCNotification And(GCNotification right)

Combines two filters using logical AND.

Combines two filters using logical XOR.

public virtual GCNotification Negate()

Negates this filter.

public virtual GCNotification Or(GCNotification right)

Combines two filters using logical OR.

public Registration Register<T>(Action<T, GCMemoryInfo> callback, T state, bool captureContext = false)

Registers a callback to be executed asynchronously on approach of GC notification.

public Task<GCMemoryInfo> WaitAsync(TimeSpan timeout, CancellationToken token = default)

Waits for GC notification asynchronously.

public Task<GCMemoryInfo> WaitAsync(CancellationToken token = default)

Waits for GC notification asynchronously.