G
Guest
Hello,
I'm writing an Application for a serial device, which is using a
USB-to-Serial Converter. I'm polling that device for new data every 500 ms.
So this is working fine.
But if the customer unpluggs the USB-to-Serial Converter, I get an
System.UnauthorizedAccessException on the next write operation and sometimes
an ObjectDisposedException which is not chatchable after that.
I tried many things and I can reproduce it now with some very simple lines
of code.
First I have to explain, that my System - after playing a lot with plugging
and unplugging USB-to-Serial devices - sometimes takes a few seconds until it
recognizes the device to be unplugged. So I have a few seconds between
unplugging the device and hearing the unplug sound of the system.
Now my simple example:
In a Windows Form, I create a SerialPort and open that port.
Now I unplugg the USB-to-Serial converter.
Then I close the SerialPort (before the unplugg sound is played)
Then, after a few seconds, exactly when the unplugged sound is played, I get
that "ObjectDisposedException, safe handle has been closed".
I also tried to create a new port instead of closing it. In this case I get
the UnauthorizedAccessException when the unplugged sound is played - or when
the form is closed.
As I figured out, if any command of the SerialPort is called between
unplugging the device and the unplugg sound of the system, a not catchable
exception will be thrown.
How can I avoid that Exception?
Or is it possible to catch (and ignor) it?
Thanks in advance.
Robert
I'm writing an Application for a serial device, which is using a
USB-to-Serial Converter. I'm polling that device for new data every 500 ms.
So this is working fine.
But if the customer unpluggs the USB-to-Serial Converter, I get an
System.UnauthorizedAccessException on the next write operation and sometimes
an ObjectDisposedException which is not chatchable after that.
I tried many things and I can reproduce it now with some very simple lines
of code.
First I have to explain, that my System - after playing a lot with plugging
and unplugging USB-to-Serial devices - sometimes takes a few seconds until it
recognizes the device to be unplugged. So I have a few seconds between
unplugging the device and hearing the unplug sound of the system.
Now my simple example:
In a Windows Form, I create a SerialPort and open that port.
Now I unplugg the USB-to-Serial converter.
Then I close the SerialPort (before the unplugg sound is played)
Then, after a few seconds, exactly when the unplugged sound is played, I get
that "ObjectDisposedException, safe handle has been closed".
I also tried to create a new port instead of closing it. In this case I get
the UnauthorizedAccessException when the unplugged sound is played - or when
the form is closed.
As I figured out, if any command of the SerialPort is called between
unplugging the device and the unplugg sound of the system, a not catchable
exception will be thrown.
How can I avoid that Exception?
Or is it possible to catch (and ignor) it?
Thanks in advance.
Robert