title: How to run c# console application .exe in background?
body: <p>I'm trying to simulate the updating of a database using commands in cmd but I need to be able to run the .exe that calls these from a cmd and continue to use that same cmd window.</p>
  <p>I've attempted to just hide the window that Process will create, which works fine, however when I run myFile.exe it hangs up the cmd window used to run it until the process is finished. This is a problem because when completed my code will be running for hours at a time and I would rather not keep a dead cmd window open just to run the application.</p>
  <p>Currently ProcessWindowStyle.Hidden is what I am using to call the command and hide the window, the command sets the first value in my database to the numbers 0-25 every half second but I can't use the cmd window until it reaches 25 and exits the application.</p>
  <pre class="lang-cs prettyprint-override"><code>static void Main(string[] args)
  { 
      int Number_Of_Args = args.Length;
      int[] Arguments = Check_Args(args, Number_Of_Args);
      Run_Command(Arguments);
  }
  
  public static void Run_Command(int[] Arguments)
  {
      System.Diagnostics.Process process = new System.Diagnostics.Process();
      System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
      startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
      startInfo.FileName = &quot;cmd.exe&quot;;
  
      for (int i = 0; i &lt;=25 ; i++)
      {
          startInfo.Arguments = &quot;/C dbset 1 = &quot; + i.ToString();
          process.StartInfo = startInfo;
          process.Start();
          Thread.Sleep(500);
      }
  }
  </code></pre>
  <p>When complete I need the for loop to be a while loop that will continuously change the database values and therefor having it hang in the cmd window is not ideal. My final goal is be able to call my application from cmd with &quot;C:\filelocation Simulation.exe arg1 arg2 arg3&quot; and have it start running and updating the database while I go about whatever other business I have with the cmd window at the time.</p>
  <p>EDIT: I can call Start Simulation.exe and it will open a new cmd window and run the code in a new window and leaves me in control of the original window. If I could either have Start Simulation.exe hide the new cmd window OR have the code default to Start a new window when called simply as Simulation.exe that could be what I need, although having both would be the best, like previously stated, so that I can run the command and not lose control of the current cmd window.</p>