Hosting Options
On this page
Namespace: Nalix.Hosting.Options
Assembly: Nalix.Hosting
HostingOptions configures server bootstrap behavior (Bootstrap.Initialize()), console startup diagnostics, .NET ThreadPool minimum thread floors, global unhandled exception logging, and Windows 1ms timer resolution (timeBeginPeriod(1)).
Source Mapping
src/Nalix.Hosting/Options/HostingOptions.cssrc/Nalix.Hosting/Bootstrap.cssrc/Nalix.Hosting/Internal/DiagnosticChannel.cs
Bootstrap Lifecycle (Bootstrap.Initialize())
Nalix.Hosting invokes Bootstrap.Initialize() automatically via a [ModuleInitializer] when the assembly is loaded:
- Dedicated Server Config Path: Calls
ConfigurationManager.Instance.SetConfigFilePath(Path.Combine(Directories.ConfigurationDirectory, "server.ini"))so server settings are isolated inserver.ini(avoiding collisions with clientdefault.ini). - Option Materialization: Touches all framework, codec, network, runtime, and hosting option classes via
ConfigurationManager.Instance.Get<TOptions>()and callsConfigurationManager.Instance.Flush()so a completeserver.initemplate is written to disk. - ThreadPool Tuning: Applies
MinWorkerThreadsand/orMinCompletionPortThreadsviaThreadPool.SetMinThreads(...)when either property is> 0. - Global Exception Handlers: When
EnableGlobalExceptionHandlingistrue, subscribes toAppDomain.CurrentDomain.UnhandledException(logging critical failures and flushingConfigurationManagerif terminating) andTaskScheduler.UnobservedTaskException(logging and callinge.SetObserved()). - High-Precision Windows Timer: When
EnableHighPrecisionTimeristrueon Windows, callswinmm.dlltimeBeginPeriod(1)to raise OS timer resolution to1 ms. - Interactive Startup Banner: When
Environment.UserInteractive && !DisableStartupBanner, prints the Nalix startup banner, runtime metadata (Version,PID,OS,Arch,Runtime,Config,GC Mode,Timer,Processors,Local IP,Public IPfromNALIX_PUBLIC_IP), and emits a warning if Workstation GC is active instead of Server GC.
Properties and Defaults
| Property | Type | Default | Validation | Description |
|---|---|---|---|---|
DisableConsoleClear | bool | false | None | If true, prevents Console.Clear() before printing the startup banner (also skipped automatically when console output is redirected). |
DisableStartupBanner | bool | false | None | If true, suppresses the ASCII banner and [INIT] diagnostic table on startup. |
MinWorkerThreads | int | 0 | [ValueRange(0, int.MaxValue)] | Minimum ThreadPool worker threads (0 keeps the OS/.NET default; recommended: ProcessorCount * 2). |
MinCompletionPortThreads | int | 0 | [ValueRange(0, int.MaxValue)] | Minimum ThreadPool I/O completion port (IOCP) threads (0 keeps the OS/.NET default). |
EnableGlobalExceptionHandling | bool | true | None | Registers UnhandledException and UnobservedTaskException handlers during bootstrap. |
EnableHighPrecisionTimer | bool | true | None | Calls timeBeginPeriod(1) on Windows for 1ms timer resolution (automatically paired with timeEndPeriod(1) on process exit). |
Validate() executes this.ValidateDataAnnotations().
Process Exit Cleanup (Bootstrap.OnProcessExit)
Bootstrap subscribes to Console.CancelKeyPress and AppDomain.CurrentDomain.ProcessExit. On process shutdown it:
- Cancels all running background workers via
InstanceManager.Instance.GetExistingInstance<TaskManager>()?.CancelAllWorkers(). - Flushes pending configuration changes via
ConfigurationManager.Instance.Flush(). - Disposes
InstanceManager.Instance(which disposes registered services such asConnectionGuard, flushing the progressive ban database to disk). - Calls
timeEndPeriod(1)on Windows iftimeBeginPeriod(1)was enabled. - Disposes the
DiagnosticChannel.
INI Configuration (server.ini)
[Hosting]
; Hosting configuration — controls startup diagnostics, console behavior, and lifecycle settings
DisableConsoleClear = false
DisableStartupBanner = false
MinWorkerThreads = 0
MinCompletionPortThreads = 0
EnableGlobalExceptionHandling = true
EnableHighPrecisionTimer = true