I have a WPF application that connects through a socket to a device and receives streaming text data (about 1 message per second). This data is then displayed in the user interface. The user can create rules such as "If the data contains" abc ", select the line" or "... make it bold", so plain text output will not be executed, it must be "rich" text.
My current solution for this is FlowDocument in my ViewModel model, which contains formatted output. The view has a FlowDocumentScrollViewer that is associated with a FlowDocument in the ViewModel.
This works, but when a FlowDocument gets large (~ 6000 lines), performance starts to deteriorate. The current algorithm limits the number of lines to 10,000, but then everything becomes even worse, until the moment when the application is unusable. When it reaches 10,000 rows, I delete the row for each row to be added, as a result of which FlowDocumentScrollViewer receives 2 update notifications for each new row.
I tried to find a way to batch delete (when we reach 10,000 rows, delete the oldest 1000 rows), but there is no bulk delete in FlowDocument. Looping 1000 times and performing removal results in 1000 update notifications and blocking the user interface.
Here is my problem, here is my question:
What is the best way to display streaming text content with WPF? I get ~ 1 message per second, each message is ~ 150 characters, and I want to save the last 10,000 messages. Am I really wrong? Are there other controls / objects that will work better?
EDIT : Here are a few more requirements
- You must be able to print the output text.
- You must be able to select and copy the output text so that it can be pasted into another document.
source
share