I've written an application which reads from a serial device at a very fast rate. The serial port object however, fails to fire the DataReceieved
event after about 20 min of continuous operation. Disconnecting and reconnecting the serial programmatically allows the event to work again but for only another 20 min.
I tried using DiscardInBuffer
after every DataReceived
event and this has appeared to have solved the problem. But the method consumes a lot of cpu time and is degrading the performance of the application. MSDN mentions that the method "Discards data from the serial driver's receive buffer.", but fails to suggest when it should be used.
When and how should DiscardInBuffer
be used, and am I using it in the correct context for my particular problem ?
Edit:
After implementing the ErrorReceived
event, the event data returned indicated the event type was an "RXOver".