Hello Guys, I am Working on a Serial Port implementation in C#. I am Getting data from SerialPort and I am adding that data to Queue type of Collection (Globally Declared). I am using BackgroundWorker thread to process data in Queue. The Problem is that. If Serial Port Stop Sending data and data Received stop Receiving data There will be still some data remain in my Queue which required processing. Is there any way Which tell me there is no data coming from SerialPort or in other words Port_dataReceived is stopped receiving any data. So that I can process whatever data is there in Queue. Because this time i will be sure that there will not be any data coming from Serial Port now and whatever the data in the queue is the last remaining data to be processed. Thanks in Advance - Chetan
views:
595answers:
1
A:
If you're using the System.IO.Ports.SerialPort, then I don't believe there is something built in. You'd need to code it yourself.
Is there a reason you can't just use the DataReceived event and process the data as it comes in?
This is tricky because you have to deal with the fact that the SerialPort listener operates on a different thread, so you may need to worry about thread safety, but you could set a global DateTime variable and update it in the DataReceived event, and then check that in your code to see if the last time data has been received has been more than n seconds.
David Stratton
2009-07-29 15:28:52
Thanks David. Good Suggestion.
2009-07-29 15:57:49