Server/RichTextBoxTraceListener.cs
author StephaneLenclud
Mon, 06 Mar 2017 15:11:27 +0100
changeset 282 29b4bdeda281
permissions -rw-r--r--
Published v1.4.7.0
Adding back runtime dependencies.
     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 }