This works for me (using native method).
First, declare:
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();
After that, check with elegance... hahaha...:
if (GetConsoleWindow() != IntPtr.Zero)
{
Console.Write("has console");
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…