Class HealthMonitor
- Namespace
- AppHealthMonitor
- Assembly
- AppHealthMonitor.dll
Monitors the health and lifecycle of a single application process. Provides automatic restart capabilities, resource monitoring, and port health checks.
public sealed class HealthMonitor : IAsyncDisposable
- Inheritance
-
HealthMonitor
- Implements
- Inherited Members
Constructors
HealthMonitor(AppConfig, IReadOnlyList<IHealthChecker>, bool, CancellationToken)
Initializes a new instance of the HealthMonitor class.
public HealthMonitor(AppConfig config, IReadOnlyList<IHealthChecker> healthCheckers, bool headless, CancellationToken cancellationToken)
Parameters
configAppConfigThe application configuration. Must have TryApplyDefaultsAndValidate(out string) called first.
healthCheckersIReadOnlyList<IHealthChecker>The health checkers to use for port monitoring. Empty list for process-only monitoring.
headlessboolWhether to launch the process in headless mode (no window, shell execution disabled).
cancellationTokenCancellationTokenToken to signal cancellation of monitoring operations.
Exceptions
- ArgumentNullException
Thrown when config is null.
Properties
Name
Gets the display name of the monitored application, used for diagnostics and logging.
public string Name { get; }
Property Value
Methods
DisposeAsync()
Disposes of the monitor by killing any active process. Health checkers are NOT disposed here — they are shared across monitoring cycles and owned by DaemonOrchestrator.
public ValueTask DisposeAsync()
Returns
GetStatus()
Returns a snapshot of the current monitor status for diagnostics.
public HealthMonitorStatus GetStatus()
Returns
- HealthMonitorStatus
A HealthMonitorStatus representing the current state.
KillApplicationAsync()
Asynchronously terminates the monitored application process. Attempts graceful shutdown first (SIGTERM on Linux/macOS, CloseMainWindow on Windows), then force-kills if the process does not exit within the configured timeout. Uses a standalone bounded timeout (not linked to the monitoring lifecycle token) to ensure graceful shutdown is always honored, even during stop/shutdown disposal.
public Task KillApplicationAsync()
Returns
- Task
A task representing the asynchronous kill operation.
StartMonitoringAsync()
Starts the monitoring loop for the application. Continuously checks application health and performs restarts as needed. Exits when cancelled, when maximum restart attempts are exhausted, or when the initial launch fails.
public Task StartMonitoringAsync()
Returns
- Task
A task that represents the asynchronous monitoring operation.