title: How can I hide a console window?
body: <p>Question: I have a console program that shouldn't be seen.
  (It resets IIS and deletes temp files.)</p>
  
  <p>Right now I can manage to hide the window right after start like this:</p>
  
  <pre><code>static void Main(string[] args)
  {
      var currentProcess = System.Diagnostics.Process.GetCurrentProcess();
      Console.WriteLine(currentProcess.MainWindowTitle);
  
      IntPtr hWnd = currentProcess.MainWindowHandle;//FindWindow(null, "Your console windows caption"); //put your console window caption here
      if (hWnd != IntPtr.Zero)
      {
          //Hide the window
          ShowWindow(hWnd, 0); // 0 = SW_HIDE
      }
  </code></pre>
  
  <p>The problem is this shows the window for a blink of a second.
  Is there any constructor for a console program, where I can hide the window before it is shown?</p>
  
  <p>And second: </p>
  
  <p>I use</p>
  
  <pre><code>[System.Runtime.InteropServices.DllImport("user32.dll")]
  static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
  </code></pre>
  
  <p>and I don't like the 32 in it. Is there any way to do this without DllImport ? <br />
  A .NET way ?</p>