title: Why don't my event handlers fire when I'm reading from the standard output of another process
body: <p>I have a very simple C# project that has a UI process and a worker process. The worker code needs to be a process (rather than a thread) because it can be run by either the UI or by the Windows Task Scheduler.</p>
  
  <p>In the UI code, I set the <code>ProcessStartInfo.RedirectStandardOutput</code> to <code>true</code> and I register the event handlers. Then, I start the process (with <code>Process.Start()</code> and call <code>Process.BeginOutputReadline()</code>. Yet, the method that I have designated as the OutputDataReceived event handler never fires. When I run the worker process without redirecting it's standard output, I see the expected output on the console. When I turn on output redirection, I don't see anything on the console (as expected), but the event handlers don't fire either. Is there something else that I need to to read asynchronously from another process' standard output stream?</p>
  
  <p>EDIT: I've managed to replicate the problem with two simple console processes. </p>
  
  <p>First the parent:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading;
  using System.Diagnostics;
  
  namespace OutputRedirectionEventHandlerTest
  {
      class ParentProgram
      {
          static void Main(string[] args)
          {
              ProcessStartInfo processInfo = new ProcessStartInfo()
              {
                  FileName = "OutputRedirectionWorker.exe",
                  RedirectStandardOutput = true,
                  UseShellExecute = false
              };
              Process subProcess = new Process()
              {
                  StartInfo = processInfo
              };
              subProcess.OutputDataReceived += 
                  new DataReceivedEventHandler(OutputHandler);
              subProcess.Start();
              subProcess.BeginOutputReadLine();
  
  
          }
  
          static void OutputHandler(object SendingProcess, 
              DataReceivedEventArgs args)
          {
              Console.Out.WriteLine("Received from subprocess: " + args.Data);
          }
  
      }
  }
  </code></pre>
  
  <p>And then, the child:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Diagnostics;
  using System.Threading;
  
  namespace OutputRedirectionWorker
  {
      class ChildProgram
      {
          static void Main(string[] args)
          {
              Console.Out.WriteLine("Output1");
              Console.Out.WriteLine("Output2");
              Console.Out.WriteLine("Output3");
              Thread.Sleep(10000);
          }
  
      }
  }
  </code></pre>
  
  <p>No output ever gets printed by the parent.</p>