Can someone explain this message and the Environment.Exit(1) statement? I'm testing out creating a windows service in .NET 6 and this advice is shown in the Microsoft example.
https://docs.microsoft.com/en-us/dotnet/core/extensions/windows-service
If the Environment.Exit(1) statement is included, when stopping the service, it returns the error "Windows could not stop the TestService service on Local Computer. Error 1067:The process terminated unexpectedly."
If I comment out that line the service stops without the windows error.
// Terminates this process and returns an exit code to the operating system.
// This is required to avoid the 'BackgroundServiceExceptionBehavior', which
// performs one of two scenarios:
// 1. When set to "Ignore": will do nothing at all, errors cause zombie services.
// 2. When set to "StopHost": will cleanly stop the host, and log errors.
//
// In order for the Windows Service Management system to leverage configured
// recovery options, we need to terminate the process with a non-zero exit code.
Environment.Exit(1);