简体   繁体   中英

How to determine whether code is getting executed in a console app or in a windows service

如何确定代码是在控制台应用程序还是Windows服务中执行?

Whilst it's not console specific (ie this will return true when running as a winforms app as well) I've used the following

if (Environment.UserInteractive)
{
    Console.WriteLine("Hi I'm being ran as a console app");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM