?
Solved

Optimized RichTextBox

Posted on 2004-09-01
4
Medium Priority
?
1,039 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month12 days, 7 hours left to enroll

777 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