如何确定代码是在控制台应用程序还是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.