Hide Console Window

Programming C#

Sometimes console applications should run in some kind of "deamon" or "job" state without showing the console window at all.

You can achive this via code.  One possibility would be f.e.:

using System.Runtime.InteropServices;

static extern IntPtr GetConsoleWindow();

static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

const int SW_HIDE = 0;
const int SW_SHOW = 5;
var handle = GetConsoleWindow();

// Hide
ShowWindow(handle, SW_HIDE);

// Show
ShowWindow(handle, SW_SHOW);

But wait! There's no need for this piece of code.

  • Right-click the console application project and select properties
  • Select the application tab
  • Select Windows Application from the Output Type dropdown: