Solved

Optimized RichTextBox

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
global Variable - 2 functions in powershell 1 44
array not updating 8 42
aspx ascx, c# 7 42
C# Web service insert into Oracle table 8 37
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

732 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