2 years ago
#67150
slam505
.NET Framework 4.8 Environment.UserInteractive always returns true regardless if it was started in a service or not
I'm writing a program that can be ran as both a console app and as a service. Right now, it's basically:
static void Main(string[] args)
{
if (Environment.UserInteractive)
{
// Console App
// contains code that causes an error when ran as a service
}
else
{
var servicesToRun = new ServiceBase[]
{
new HostManagerService(logger)
};
ServiceBase.Run(servicesToRun);
}
}
However, the Environment.UserInteractive always returns true. I know that this is true because when I try to run the program as a service, I run into an error because this runs the console app version of the code instead of the service version. Does anyone know why this could be the case?
EDIT: To run it as a service, I find the .exe file and run, "myprogram.exe -i" in my command prompt to install the .exe as a service and then in the Services window, I right click and press start (with Allow service to interact with desktop disabled).
c#
.net
service
.net-4.8
0 Answers
Your Answer