Host Lifecycle
The host opens channels, runs background services, and releases resources in the reverse order during shutdown.
Order
ZeusHost.Create: register channels, devices, and services. Ports are not opened yet.StartAsync: open channels in registration order. Arequiredchannel failure aborts startup and rolls back opened channels;optional/degradedchannel failures are logged and recovered by reconnect.- Runtime: access objects through
Channels,Devices, andPoints; the acquisition loop polls on its interval. StopAsyncorDisposeAsync: 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.Servicesis a standardIServiceCollection; register your own services there.builder.Logging,builder.Configuration, andbuilder.Environmentexpose the Generic Host logging, configuration, and environment.app.Servicesresolves services after the host is built.- Channel startup mode defaults to
required. Usestartup: "optional"/startup: "degraded"in JSON, or passChannelStartupMode.Optional/ChannelStartupMode.DegradedAllowedwhen adding runtime channels that may fail independently. StopAsyncpauses acquisition and reconnects, then closes channels.- Calling
StartAsyncagain afterStopAsyncreopens channels. DisposeAsyncreleases process resources; after disposal, create a new host.app.IsRunningreflects whether the user started Zeus, not whether the underlying Generic Host exists.
Common Issues
- Optional or degraded channel becomes
Faultedafter startup: default reconnects will retry, or you can callOpenAsyncmanually. Required channel startup failures makeStartAsyncthrow. - Serial port remains busy after the process exits: make sure the host was disposed;
AttachZeushandles this for desktop windows.