Solved

Optimized RichTextBox

Posted on 2004-09-01
4
1,018 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
  • 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 350 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 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