title: Deadlock on out/error buffer
body: <p>Here is the code:</p>
  
  <pre><code>var output = new StringWriter();
  var error = new StringWriter();
  
  var p = new Process();
  p.StartInfo = new ProcessStartInfo
  {
      WorkingDirectory = workingDir,
      FileName = file,
      Arguments = args,
      UseShellExecute = false,
      RedirectStandardOutput = true,
      RedirectStandardError = true,
  };
  p.OutputDataReceived += (o, e) =&gt; { output.WriteLine(e.Data); };
  p.ErrorDataReceived += (o, e) =&gt; { error.WriteLine(e.Data); };
  
  p.Start();
  
  if (!p.WaitForExit((int)timeout.TotalMilliseconds))
  {
      p.Kill();
      throw new Exception("Timeout expired.");
  }
  
  string errorData = error.ToString();
  if (errorData.Length &gt; 0)
      throw new Exception(errorData);
  
  return output.ToString();
  </code></pre>
  
  <p>I would expect <code>OutputDataReceived</code> and <code>ErrorDataReceived</code> handlers to be called whenever data becomes available, however that is not happening. For a process that outputs ton of stuff into stdout this code eventually exits on <code>throw new Exception("Timeout expired.");</code>. I tried throwing some debug code into handlers, but it is never called. Isn't the whole point of specifying out/err handlers is to have them called asynchronously? </p>