Server/RichTextBoxTraceListener.cs
author StephaneLenclud
Sun, 08 Jan 2017 12:19:35 +0100
changeset 278 2481c46d1f93
permissions -rw-r--r--
Reading audio output is stopped when audio visualizers are not in used.
     1 using System;
     2 using System.Text;
     3 using System.IO;
     4 using System.Windows.Forms;
     5 using System.Diagnostics;
     6 
     7 namespace SharpDisplayManager
     8 {
     9     public class RichTextBoxTraceListener : TraceListener
    10     {
    11         RichTextBox iRichTextBox = null;
    12 
    13         public RichTextBoxTraceListener(RichTextBox aRichTextBox)
    14         {
    15             iRichTextBox = aRichTextBox;
    16         }
    17 
    18         public override void WriteLine(string aString)
    19         {
    20             //Add time stamp and new line characters
    21             Write(DateTime.Now.ToString("MM/dd HH:mm:ss.fff: ") + aString + "\r\n");
    22         }
    23 
    24         public override void Write(string aString)
    25         {
    26             //Allows iRichTextBox to be updated from different thread
    27             if (iRichTextBox.InvokeRequired)
    28             {
    29                 // Fire and forget invocation
    30                 // Using the synchronous variant Invoke tends to result in deadlock here
    31                 iRichTextBox.BeginInvoke(new MethodInvoker(delegate ()
    32                 {
    33                     iRichTextBox.Text += aString;
    34                 }));
    35             }
    36             else
    37             {
    38                 iRichTextBox.Text += aString;
    39             }
    40         }
    41 
    42     }
    43 }