Streaming data and updating screen in C#
I am dealing with a stream of data on serial port. The baud rate is 19200 kbps, leaving a shot time (about 100 ms) to process data and display the result on the screen.
There is no issue with data processing performance. The main problem is updating the screen. The application specification needs me to show data in a tabular view. Cell contexts in this view might have different colours based on the information they indicate. For example red for errors, green or blue for some kinds of messages and etc.
Currently, I am using a datagridview to display the data as it has a flexible tabular view, and its cells has ForeColor property to change the colour. But, it is too slow compared to the input data and processing rate. Specifically, when I add new rows on new data arrival or remove old rows from the beginning. To add and remove a row I use the DGV.Rows.Add(...), and DGV.Rows.RemoveAt(...) methods.
I considered two approaches:
1) Two different threads for processing data and updating UI. However, as data processing is much faster than operations on datagridview, data will be accumulated and finally slow down everything.
2) Processing data and update the screen sequentially. In this case, after processing of each message, the message will be displayed on the screen (will be added to the datagri开发者_Go百科dview), and the next will be processed after the screen update. Obviously, this way decreases the processing speed which in not desirable.
So, I am wondering if there is any better ways to handle this condition... or if I am not using the right control in terms of the performance for this purpose.
Thanks.
1 with some smart programming that does not make the griview fall behind. I am runnin a grid here that shows real time financial updates and I do not fall behind, and that grid gets more data than your 19200 baud connection holds - I pretty much get up to 10.000 data items per second. I just discard those not of visible interest. Optimize the grid presentation. Get an alterantive grid (that is made to handle tons of updates).
精彩评论