I am developing a simple serial data viewer that will be used to view data transmitted to one of the serial ports of a computer. I wrote a test application using C # and WPF; it just puts the last line read in a text block. However, it skips all the other lines. My theory is that new data is placed in a text block before WPF displays this window. However, I tried every combination of thread priorities that I can think of, and, at best, the application shows every other line; in the worst case, it shows every 20 lines.
I am running on a multi-core computer. My application consists of a text block and a button for opening / closing a port. (I tried replacing the text block with a text field, and I am observing the same problem)
My DataReceived handler:
private void MainWindow_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
string message = sp.ReadLine();
if (string.IsNullOrWhiteSpace(message))
return;
this.Dispatcher.BeginInvoke(DispatcherPriority.Send, (ThreadStart)delegate()
{
text.Text = message;
this.InvalidateVisual();
});
}
The highest priority for this application is handling the steady bandwidth of large amounts of data; Is WPF appropriate in this situation? If so, what am I doing wrong?
Cwman source
share