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

前端 未结 6 622
闹比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:35

    To determine if a .NET application is running in GUI mode:

    bool is_console_app = Console.OpenStandardInput(1) != Stream.Null;
    

提交回复
热议问题