Skip to content

Console application lifecycle

ConsoleBase<TArgContainer>.Run() executes the standardized application lifecycle — Initialize(), Execute(), Finish() — for the concrete application instance resolved by the program runner entry point.

Field Value
Operation ID OP-WIN-002
Trigger Called by program runner entry point step 8, on the container-resolved application instance.
Inputs State established by the constructor (Arguments, StartTime, injected IConsoleLogService).
Outputs Environment.ExitCode reset to 0 at the start of this method; console header/footer log lines.
Primary components ConsoleBase<TArgContainer>.Run(), Dispose()
Entry point Console\SAIF.Console\Console\ConsoleBase.cs

Steps

  1. Initialize() — abstract, app-specific one-time setup.
  2. Environment.ExitCode = 0 — set unconditionally after Initialize() returns (BR-WIN-006: a successful Initialize() always resets any pre-existing non-zero exit code before Execute() runs).
  3. Execute() — abstract, app-specific main logic.
  4. Finish() — abstract, app-specific cleanup.
  5. Separately, on Dispose() (not part of Run()): WriteFooter() then logService.Dispose() — writes the "ended at"/"ran for N seconds" lines and disposes all registered LogWriters.

Note: WriteHeader() runs earlier, in the constructor (before Run() is ever called), writing the "began at" line.

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start([Run invoked]) --> Init[Initialize]
    Init --> Reset[Environment.ExitCode = 0]
    Reset --> Execute[Execute]
    Execute --> Finish[Finish]
    Finish --> EndOk([Run returns])
    EndOk -.->|On Dispose| Footer[WriteFooter + logService.Dispose]

Failure and edge-case behavior

  • Environment.ExitCode is always reset to 0 after Initialize() succeeds, discarding any prior non-zero value set before this call — this happens regardless of what Execute()/Finish() subsequently do.
  • WriteFooter() and log-service disposal run only on Dispose(), not as part of Run() — a consuming application that does not dispose the resolved ConsoleBase instance never writes the footer or flushes/disposes log writers.

Sources

  • Console\SAIF.Console\Console\ConsoleBase.cs