Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何确定代码是在控制台应用程序还是在 Windows 服务中执行的?
虽然它不是特定于控制台的(即,这也将在作为 winforms 应用程序运行时返回 true),但我使用了以下内容
if (Environment.UserInteractive) { Console.WriteLine("Hi I'm being ran as a console app"); }