?
Solved

Optimized RichTextBox

Posted on 2004-09-01
4
Medium Priority
?
1,046 Views
Last Modified: 2008-03-06
I need to write a C#, windows forms control like RichTextEdit native control. I need to be able to append text to the control as fast as possible even if the control contains already 5k lines or more.

The control is going to be used in a PC "tracer" application that is connected with RS232 through serial cable to an embadded system and is used to debug it. The same thread that is reading the traces from the serila cable is writing the traces to the control. The traces are coming fast (that's why the control should be "optimized") and a single trace session can last several hours (that's why the control should handle big amounts of data.)

The control should get the text to be appended as a 8-bit unsafe char* or as an undsafe w_char* becuase it is supposed to be integrated with an unmanaged C++ code:
// appends an ASCII string with the color in_uColor and booldness such as
// specified in in_bBold to the RichTextBox and to the log file.
// Scrolls the RichTextBox to the bottom to show the newly added text.
bool AppendText(sbyte* in_szText, int in_uColor, bool in_bBold);
      
// appends a wide-char string with the color in_uColor and booldness such as
// specified in in_bBold to the RichTextBox and to the log file.
// Scrolls the RichTextBox to the bottom to show the newly added text.
bool AppendText(char* in_szText, int in_uColor, bool in_bBold);

I thought about creating a subordinate thread, or at least a queue, where the new rows can be inserted in to a transient table as fast as possible, then that table at periodic intervals (even if it's every 200 miliseconds) would flush out what it had to the UI and to the StreamBuffer of the file.

I would appreciate opinions and guidance from someone who has experience with optimized, Real-Time WinForms controls:
What are the fastest ways possible to append to a RichTextBox ASCII strings and w_char* strings, as described above ?
What are the fastest ways possible to append to a file ASCII strings and w_char* strings, as described above ?
Are there code examples for things such as that ?
Does my idea about creating subordinate thread make sense ? Are there better ways to achieve fast performance ?
Do you know a good commercial optimized RichText controls such as that for windows forms (I could spend up to 300$) ?

Thanks.

0
Comment
Question by:ronron771
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11951997
"The control is going to be used in a PC "tracer" application that is connected with RS232 through serial cable to an embadded system and is used to debug it. The same thread that is reading the traces from the serila cable is writing the traces to the control. The traces are coming fast (that's why the control should be "optimized") and a single trace session can last several hours (that's why the control should handle big amounts of data.) " you shouldnt do this ... only the thread that creates the control should write to it, this can produce unpredictable results see this http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondevelopingmultithreadedwindowsformscontrol.asp for how to use Invoke() or BeginInvoke (async version) to broker the calls.

As for writing to the file, this should be quite easy to catch up with ...I don't think the RTF will keep up with 200 ms multi line writes though.

0
 
LVL 10

Expert Comment

by:eternal_21
ID: 11955945
You can't possibly read the output in real time if speed is a factor... why don't you save the input to a file or in memory, and then update the RichTextBox, at regular intervals?
0
 

Author Comment

by:ronron771
ID: 11962194
What is the most efficiant way to update the RichTextBox ? Let's say that I'll write the text to a file and would like to update my RichTextBox every 500 ms. I guess the calling the RTB's Load method every 500 ms is not very efficient. What is the right way then ?
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 1050 total points
ID: 11963621
well I would probably use a shared file ... (one thread writes one thread reads) then I would use a readtoend() on the file ... dump your text via appendtext or a similar method (selectionstart then set text) so that you are only adding text.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question