title: Serial Port Asynchronous Read Using Base Stream
body: <p>I have found that the C# serial port implementation can be pretty flaky when it comes to the <code>datarecieved</code> event, so I decided to implement my own asynchronous read using the underlying <code>stream</code>. I implemented a continuous read loop that I would expect to get a stack overflow due to recursion, but for some reason it doesn't. Here is the code:</p>
  
  <pre><code>SerialPort port = new SerialPort("COM0");
  Stream bar = port.BaseStream;
  Action foo = null;
  foo = () =&gt;
  {
       byte[] buf = new byte[256];
       AsyncCallback callback = ar =&gt;
       {
           int bytesRead = bar.EndRead(ar);
           //call event sending recieved bytes to main program
           foo();
       };
       bar.BeginRead(buf, 0, 8, callback, null);
  };
  foo();
  </code></pre>
  
  <p>I suspect the recursive calls to <code>foo</code> to keep making new stack frames until the system would crash, but apparently that is not the case.</p>
  
  <p>So my question is, why do the recursive calls to <code>foo</code> not cause a stack overflow?</p>