With debugger enabled, the output window was not directly related to the process, so Process.GetCurrentProcess().MainWindowHandle didn't work. This way works 100% for me:
Console.Out != TextWriter.Null