0

I run a web API as windows service with Microsoft.Extensions.Hosting.WindowsService.

This allows me to run it as service or as console app (if I just click the exe). Actually pretty sweet.

But is there a way to detect how it is running (console app or windows service) at runtime? Would be interersting to have this in the logs ...

monty
  • 7,888
  • 16
  • 63
  • 100
  • @Dai Please help me to understand how the StartTime would help me figuring out if it is running as windows service or console app. I don't get the hint. – monty Aug 10 '22 at 12:45
  • My apologies - I misread "But is there a way to detect how it is running" as "But is there a way to detect how **long** it is running" - _whoops_. – Dai Aug 10 '22 at 12:57
  • 1
    Here: https://stackoverflow.com/questions/414098/detect-if-code-is-running-as-a-service - use `WindowsServiceHelpers.IsWindowsService()` to check if your code is running within a process running as a Windows Service. – Dai Aug 10 '22 at 12:58

0 Answers0