title: "Safe handle has been closed" with SerialPort and a thread in C#
body: <p>Good afternoon everybody!</p>
  
  <p>I have this threaded <code>SerialPort</code> wrapper that reads in a line from the serial port. Here is my thread's code.</p>
  
  <pre><code>protected void ReadData()
  {
       SerialPort serialPort = null;
       try
       {
           serialPort = SetupSerialPort(_serialPortSettings);
           serialPort.Open();
  
           string data;
           while (serialPort.IsOpen)
           {
               try
               {
  
                   data = serialPort.ReadLine();
                   if (data.Length &gt; 0)
                       ReceivedData(serialPort, new ReceivedDataEventArgs(data));
  
               }
               catch (TimeoutException)
               {
                   //  No action
               }
           }
       }
       catch (ThreadAbortException)
       {
           if (serialPort != null)
               serialPort.Close();
       }
  }
  </code></pre>
  
  <p>when I call <code>myThread.Abort();</code> I get an exception (with no line or reference to code) "Safe handle has been closed". Can anyone spot what I am doing wrong? Thanks.</p>
  
  <p>By the way, I have a <code>Start()</code> and a <code>Stop()</code> that creates the thread and aborts the thread, respectfully.</p>