How to tell if there is a console

前端 未结 10 2212
庸人自扰
庸人自扰 2020-12-14 16:34

I\'ve some library code that is used by both console and WPF apps. In the library code, there are some Console.Read() calls. I only want to do those input rea

10条回答
  •  春和景丽
    2020-12-14 16:56

    if (Environment.UserInteractive)
    {
        // A console is opened
    }
    

    See: http://msdn.microsoft.com/en-us/library/system.environment.userinteractive(v=vs.110).aspx

    Gets a value indicating whether the current process is running in user interactive mode.

提交回复
热议问题