How to determine if starting inside a windows service?

前端 未结 6 785
半阙折子戏
半阙折子戏 2021-02-15 16:37

Currently I\'m checking it in the following way:

if (Environment.UserInteractive)
    Application.Run(new ServiceControllerForm(service));
else
    ServiceBase.R         


        
6条回答
  •  迷失自我
    2021-02-15 17:31

    Also, it must be noted, that Environment.UserInteractive always returns true in .NET Core, even if it is running as a Windows Service.

    For the time being, best method seems to be this one from ASP.NET Core.

    Sources: .NET Core 2.2 .NET Core 3.1

提交回复
热议问题