title: Simple Text Display Window
body: <p>I am trying to find/develop a very lightweight method to display text in a pane for my desktop application. Other than setting a single font for all text, I have no requirements for text formatting. I have tried using a TextBox, TextBlock, and various observable collections. Computational efficiency is paramount.</p>
  
  <p>The text is created by the application, and is never modified by the user. The overriding requirement is that the application typically generates text at from 100 to 700 lines per second with a peak rate of 1900 lines per second. It is not unusual for the application to run for several days. Ideally, the display would scroll continuously so that the last line added was always visible.</p>
  
  <p>My current implementation uses a TextBox (For longer periods, I currently have no choice but to disable text display). Things I have tried include:</p>
  
  <ul>
  <li>setting IsUndoEnabled="False"</li>
  <li>removing the first line of text for every line of text added after n (usually 1000). This was really ugly and prompted me to try redesigning it as MVVM.</li>
  <li>using an Observable Collection or a BindingList with a ListView (ala
  MVVM) (Suprisingly this was worse than the TextBox even with the following) </li>
  <li>suppressing collection/list changed so that UI updates were deferred
  to 'idle' periods.</li>
  </ul>
  
  <p>I can provide more details on what I have tried, but I didn't want to start by writing a book. </p>
  
  <p>This is my current XAML implementation:</p>
  
  <pre><code>&lt;TextBox Grid.Row="1" Name="tbTraceLog" IsReadOnly="True" IsUndoEnabled="False" VerticalScrollBarVisibility="Auto" FontFamily="Courier New"/&gt;
  </code></pre>
  
  <p>And in codebehind:</p>
  
  <pre><code>    for (icount = 0; icount &lt; tlData.stringcount; icount++)
      {
          tbTraceLog.AppendText(tlData.s[icount]);          // TextBox implementation
          if (tbTraceLog.LineCount &gt; 1000)
          {
              // Remove one line
              tbTraceLog.Text = tbTraceLog.Text.Substring(tbTraceLog.Text.IndexOf('\n')+1);
          }
      }
      tbTraceLog.ScrollToEnd();
  </code></pre>
  
  <p>Is there a more basic text rendering class where I can start? What classes does TextBlock/TextBox inherit from?</p>