20

I am making a WPF application and I want to release a beta version of the application, for that I am adding a Button named "debug" Which will essentially show/hide the console window. I am writing appropriate message on the console after each event occurs so This will help users to report back the problem that they are having by looking at the messages on the console .

Sorry for the background story (if it's not helpful). I essentially need to know how to show/hide console windows dynamically in c# .

rajat
  • 3,415
  • 15
  • 56
  • 90
  • 1
    Have you considered using a "real" logger like log4net instead of console outputs? http://logging.apache.org/log4net/ – Tim S. Jul 22 '12 at 12:45
  • Yup , but for my level of requirement. I am comfortable with the console output . – rajat Jul 22 '12 at 12:48
  • Why don't you just open a WPF window that shows the debug lines you want to show? You can clear it on close and write while it is opened. – Mare Infinitus Jul 22 '12 at 13:03

1 Answers1

36

Do you think now I understood the question?

[DllImport("Kernel32")]
public static extern void AllocConsole();

[DllImport("Kernel32")]
public static extern void FreeConsole();


private void button1_Click(object sender, EventArgs e)
{
    AllocConsole();
    Console.WriteLine("test");
}
L.B
  • 114,136
  • 19
  • 178
  • 224