title: Loading bar while cmd.exe is running
body: <p><strong>What I'm trying to do:</strong></p>
  
  <p>Pass a command to .cmd, show a loading bar while the command executes, exit cmd and display a message box after progress bar is full</p>
  
  <p><strong>What's happening:</strong></p>
  
  <p>When I click the button that sends the command, the application hangs, the command is executed, but CMD never exits after it's finished, so the application remains frozen (until I manually close cmd.exe). I also have no idea how to display a loading bar while the command executes. When the loading bar is full, that's when I'll display the message box.</p>
  
  <p><strong>My code:</strong></p>
  
  <pre><code>Process p = new Process();
  p.StartInfo.FileName = "cmd.exe";
  p.StartInfo.WorkingDirectory = @"C:\"
  p.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
  p.StartInfo.UseShellExecute = false;
  p.StartInfo.RedirectStandardOutput = true;
  p.StartInfo.RedirectStandardInput = true;
  p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  p.Start();
  p.StandardInput.WriteLine(Command_That's_Called);
  </code></pre>
  
  <p>^ Which gets executed upon a button_Click event.</p>
  
  <p><strong>Things I've tried:</strong></p>
  
  <pre><code>p.WaitForExit(); // still hangs
  </code></pre>
  
  <p>Also threading, but I got an error like "accessed from thread other than one it was created on".</p>
  
  <p>Regarding CMD not closing, I'd just kill it after a certain amount of time, but it the length of time for the command to complete depends on various things. </p>