Description
I am working on creating a Windows service in .NET 6 using BackgroundService. However, I'm encountering an issue where the Windows service transitions to the "running" state as soon as ExecuteAsync starts executing. In my specific use case, I have a time-consuming method call inside ExecuteAsync, and I don't want the service to report that it's in the 'Running' state until this method call is completed. This is causing a problem because another application is monitoring the Windows service state and incorrectly assumes that it's in the 'Running' state while the internal method call is still in progress.
Previously, I used Topshelf with .NET Framework, and it didn't have this issue. Unfortunately, Topshelf is not supported in .NET 6.
Is there an alternate method or approach I can use to ensure that the Windows service doesn't transition to the 'Running' state until the internal method call is completed? I am open to alternative methods that do not necessarily depend on BackgroundService.
Any insights or suggestions would be greatly appreciated.