title: What can happen in two concurrent NetworkStream.BeginWrite calls?
body: <p>I have two methods on my <code>Sender</code> class:</p>
  
  <pre><code>public void SendMessage(OutgoingMessage msg)
  {
      try
      {
          stream.BeginWrite(msg.TcpData, 0, 16, messageSentCallback, msg);
      }
      catch
      {
          // ...
      }
  }
  
  private void messageSentCallback(IAsyncResult result)
  {
      stream.EndWrite(result);
  
      if (result.IsCompleted)
          onDataSent(result.AsyncState as OutgoingMessage);
  }
  </code></pre>
  
  <p>Other parts of the program can call (if they have an access to the Sender) the <code>SendMessage()</code> method. Since the program works in multi-threading environment, multiple threads have access to the Sender object.</p>
  
  <p>I have <strong>2 questions:</strong></p>
  
  <p><strong>Q1)</strong> Would making two concurrent calls to the <code>SendMessage</code> method be able to mess up the TCP communication (by filling the TCP outgoing buffer with mixed data)?</p>
  
  <p><strong>Q2)</strong> Would enclosing the <code>stream.BeginWrite()</code> call into the <code>lock { }</code> solve this problem?</p>
  
  <p>As far as I understand, the call to BeginWrite simply stores the data into the TCP outgoing buffer. Is that right?</p>