Solved

Optimized RichTextBox

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now