title: How to wait until my batch file is finished
body: <p>I'm  doing a program where I need to start cmd and there start up a batch file. The problem  is that I'm using <code>MyProcess.WaithForexit();</code>  and  I think it does not wait until the batch file processing is  finished. It just waits until the cmd is closed. My code so far:</p>
  
  <pre><code>System.Diagnostics.ProcessStartInfo ProcStartInfo =
      new System.Diagnostics.ProcessStartInfo("cmd");
      ProcStartInfo.RedirectStandardOutput = true;
      ProcStartInfo.UseShellExecute = false;
      ProcStartInfo.CreateNoWindow = false;
      ProcStartInfo.RedirectStandardError = true;
      System.Diagnostics.Process MyProcess = new System.Diagnostics.Process();
      ProcStartInfo.Arguments = "/c start batch.bat ";
      MyProcess.StartInfo = ProcStartInfo;
      MyProcess.Start();
      MyProcess.WaitForExit();
  </code></pre>
  
  <p>I need to wait until the batch file is finished. How do I do that? </p>