问题
Is there a way to check whether a program is in console or windows mode from within the application itself? I know that Read and ReadLine can somehow detect this, but how?
回答1:
You should be able to check to see if Console.In == StreamReader.Null;
If this is true, there is no console attached. For example, the following works properly for this:
public static bool IsConsoleApplication
{
get { return Console.In != StreamReader.Null; }
}
来源:https://stackoverflow.com/questions/10957440/how-to-detect-internally-whether-the-application-is-in-console-or-windows-mode-i