xriba
✅ Hosted Service running as Windows Service
I have an application running as a Windows Service and I'd like to run some code after the system starts and before it shuts down.
I have tried using HostedServices and everything works fine if I manually start and stop the service. However, it does not work when starting or shutting down the system.
Here is a simplified version of my service, I can also provide an
.exe
if necessary.
During StartAsync
I'm executing a network call, but upon reviewing the logs after booting the system, I see this exception:
System.Net.Http.HttpRequestException: No such host is known.
(Presumably a DNS error due to host not being resolved yet.)
Followed by the Application Started event.
Additional details:
As for StopAsync
, I believe the method is not executing as I see no logs at all.19 replies