We also use the FTDI driver and have the same issue. Unfortunately, there isn't much you can do about it. One strategy is to close the port whenever it's not in use. We also instruct our users to never remove the device during program operation unless instructed to do so.
You may benefit from using an object that detects USB connect/disconnect events. WMI provides functionality for this. I use it to make sure I don't try to connect to the FTDI device immediatley after is has been connected. You could tweak the code to fire events on disconnect, which will possibly allow a more graceful close. See the code example below for ideas:
using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
namespace DiagnosticControllerComm
{
class USBInsertRemoveDetect : IDisposable
{
public delegate void EventArrivedDelegate(object sender, EventArrivedEventArgs e);
public event EventArrivedDelegate EventArrived;
ManagementEventWatcher m_watcher = null;
public void Start()
{
WqlEventQuery query;
ManagementScope scope = new ManagementScope("root\\CIMV2");
scope.Options.EnablePrivileges = true;
query = new WqlEventQuery();
query.EventClassName = "__InstanceOperationEvent";
query.WithinInterval = new TimeSpan(0,0,0,0,500);
query.Condition = @"TargetInstance ISA 'Win32_USBControllerDevice'";
m_watcher = new ManagementEventWatcher(scope, query);
m_watcher.EventArrived += new EventArrivedEventHandler(UsbEventArrived);
m_watcher.Start();
}
public void UsbEventArrived(object sender, EventArrivedEventArgs e)
{
if (EventArrived != null)
{
EventArrived(sender, e);
}
}
#region IDisposable Members
public void Dispose()
{
m_watcher.Dispose();
}
#endregion
}
}