I have a service, a 4.7.2 one to be exact, that’s running our a BackgroundService
(services.AddHostedService<MagicService>()
)
I have implemented the public override async Task StopAsync(CancellationToken stoppingToken)
method, added some logs to see that it actually being called, and it indeed seems to work.
Upon calling taskkill /f /im MagicProcess.exe
my process stops, the issue is that there is an error logged in the Event Viewer:
The Magic Service service terminated unexpectedly. It has done this 6 time(s). The following corrective action will be taken in 60000 milliseconds: Restart the service.
In this case, I am not getting the log messages from the StopAsync
method, which makes sense since this is a force kill.
I am wondering why is my process triggering that error, while others aren’t.
What am I missing?
What I am trying to do is to handle/prevent the Event Viewer error.
Thanks!
2