简体   繁体   English

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

[英]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 虽然它不是特定于控制台的(即,当作为winforms应用程序运行时也会返回true),我使用了以下内容

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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