Class ServerStateProvider
Manages the operational lifecycle state of a ServerApp instance.
public sealed class ServerStateProvider : IServerStateProvider, IDisposable
- Inheritance
-
ServerStateProvider
- Implements
- Inherited Members
Remarks
👉 This class works with IConfiguration rather than IOptions<TOptions> because it must be created before the application is fully configured, and must also survive the destruction of the application host in case of a hard crash.
Constructors
ServerStateProvider(IConfiguration)
Manages the operational lifecycle state of a ServerApp instance.
public ServerStateProvider(IConfiguration configuration)
Parameters
configurationIConfiguration
Remarks
👉 This class works with IConfiguration rather than IOptions<TOptions> because it must be created before the application is fully configured, and must also survive the destruction of the application host in case of a hard crash.
Properties
ProcessTokenSource
Gets the CancellationTokenSource that expires when an Exit notification is handled.
public CancellationTokenSource ProcessTokenSource { get; }
Property Value
Remarks
⚠️ This token terminates the server process. The process should exit with the current ExitCode.
ShutdownRequestTokenSource
Gets a CancellationTokenSource that expires when a Shutdown request is handled.
public CancellationTokenSource ShutdownRequestTokenSource { get; }
Property Value
State
Gets the current ServerState.
public ServerState State { get; }
Property Value
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
OnExit()
Sets the server state to ExitingServerState if the current state is StartingServerState or ShuttingDown, otherwise throws an InvalidServerStateException;
cancels the ProcessToken (causes an immediate process exit).
public void OnExit()
Exceptions
OnInitialize()
Sets the server state to InitializingServerState if the current state is StartingServerState, otherwise throws an InvalidServerStateException.
public void OnInitialize()
Exceptions
OnInitialized()
Sets the server state to RunningServerState if the current state is InitializingServerState, otherwise throws an InvalidServerStateException.
public void OnInitialized()
Exceptions
OnShutdown()
Sets the server state to ShuttingDown if the current state is StartingServerState or RunningServerState,
otherwise throws an InvalidServerStateException; cancels the RequestToken.
public void OnShutdown()
Exceptions
OnTraceMessages()
Sets the server state to RunningServerState with tracing enabled.
public void OnTraceMessages()
OnTraceOff()
Sets the server state to RunningTracelessServerState.
public void OnTraceOff()
OnTraceVerbose()
Sets the server state to RunningServerState with verbose tracing enabled.
public void OnTraceVerbose()