title: Detecting USB Serial Adapter Being Physically Disconnected
body: <p>First, I want to say that I know there are versions of this point already on this site and others detailing issues w/ USB Serial Adapters and processing their physical disconnect in someone's application.  I have reviewed several of those discussions and tried the various suggestions without any success.  Maybe I am missing something but maybe I am not. At this point, I have lost track of how many and which ones I have tried and I am looking to start things over fresh from this post and not just rehash old items.</p>
  
  <p>To sum up most of the original posts with the most recent one being from at least within the past year, there is has been a known problem in Windows/development handling of USB Serial Adapters that are unplugged.  Some of the posts/solutions center around an unhandled/uncatchable exception that happens when closing the serial port and a fix in .NET 4.0 that is supposed to resolve this and, I think, allow for the event/exception to be caught.</p>
  
  <p>What I am doing and experiencing is this:</p>
  
  <p>I have a .NET 4.0 Service application written in C# that opens a COM port and listens for data using the built-in SerialPort class.  This data is then reported possibly to other local applications or remotely to other locations.  I am testing using a Tripp Lite USB to Serial Port adapter but the actual report of a problem was from someone using a laptop that has an internal USB to Serial Port adapter device that will from time to time "disconnect" and "reconnect" from/to the Windows OS.  I am simulating the problem w/ my device by physically disconnecting the USB device while the port is open in my Windows Service application.</p>
  
  <p>What I am seeing in my testing/debugging is that there is no reaction to the disconnection or reconnection of the USB device.  I am receiving data and that flow of data just stops to the Service application.  If I reconnect the device, the COM port is still open to the application but there is no new data.  If I close the port, there is no "application blow up" / UnhandledException error.  The port closes and the application stops normally.  At no point in time, do I receive a catchable exception which is what I would like to see happen.  If I start the application, data starts to flow again.</p>
  
  <p>I want the application to know when the USB Serial/COM port is removed from the system preferably with some kind of exception at the SerialPort level that would allow me to catch the exception, close the port, and go into "reopen port mode" until the device is "reconnected" to the PC.  Is this going to be possible in this manner around the SerialPort class or do I need to pursue a solution centered around the generic "USB Device" being disconnected rather than the "Serial Port" being disconnected?  (I have my application programmatically determining that the device is an USB device already rather than having to flag it as such in preparation for the latter...............)</p>
  
  <p>Thanks,
  Mark</p>