title: C# System.ArgumentException: Destination array was not long enough
body: <p>I have a generic Queue object which is fed from a SerialPort.DataReceived method.</p>
  
  <p>Occasionally I get exception "Destination array was not long enough" when calling the ToArray() method. The code:</p>
  
  <pre><code>        byte[] tmpArray;
  
          try
          {
              tmpArray = queue.ToArray();
          }
          catch (Exception ex) 
          {
  </code></pre>
  
  <p>For the record: queue.Count never exceeds 500. </p>
  
  <p>Although this is most likely a thread problem, I do not understand the exception. When will a destination array be too short in a queue's ToArray() method?</p>
  
  <p>If this is a thread problem, what is the best practice when it comes to getting data from a SerialPort to a Queue?</p>
  
  <p>BTW: I lock queue before writing. Perhaps I should lock it before ToArray() as well?</p>