How can a C# Windows Console application tell if it is run interactively

前端 未结 6 635
闹比i
闹比i 2020-12-03 02:54

How can a Windows console application written in C# determine whether it is invoked in a non-interactive environment (e.g. from a service or as a scheduled task) or from an

6条回答
  •  余生分开走
    2020-12-03 03:38

    A possible improvement of Glenn Slayden's solution:

    bool isConsoleApplication = Console.In != StreamReader.Null;
    

提交回复
热议问题