Skip to main content

Host Lifecycle

The host opens channels, runs background services, and releases resources in the reverse order during shutdown.

Order​

  1. ZeusHost.Create: register channels, devices, and services. Ports are not opened yet.
  2. StartAsync: open channels in registration order. A required channel failure aborts startup and rolls back opened channels; optional / degraded channel failures are logged and recovered by reconnect.
  3. Runtime: access objects through Channels, Devices, and Points; the acquisition loop polls on its interval.
  4. StopAsync or DisposeAsync: stop acquisition and close channels.
await using var app = ZeusHost.Create(builder =>
{
builder.AddVirtualChannel("meter");
});

await app.StartAsync();
// ... application work ...
await app.StopAsync();

Notes​

  • builder.Services is a standard IServiceCollection; register your own services there.
  • builder.Logging, builder.Configuration, and builder.Environment expose the Generic Host logging, configuration, and environment.
  • app.Services resolves services after the host is built.
  • Channel startup mode defaults to required. Use startup: "optional" / startup: "degraded" in JSON, or pass ChannelStartupMode.Optional / ChannelStartupMode.DegradedAllowed when adding runtime channels that may fail independently.
  • StopAsync pauses acquisition and reconnects, then closes channels.
  • Calling StartAsync again after StopAsync reopens channels.
  • DisposeAsync releases process resources; after disposal, create a new host.
  • app.IsRunning reflects whether the user started Zeus, not whether the underlying Generic Host exists.

Common Issues​

  • Optional or degraded channel becomes Faulted after startup: default reconnects will retry, or you can call OpenAsync manually. Required channel startup failures make StartAsync throw.
  • Serial port remains busy after the process exits: make sure the host was disposed; AttachZeus handles this for desktop windows.