4 using System.Windows.Forms;
5 using System.Diagnostics;
7 namespace SharpDisplayManager
9 public class RichTextBoxTraceListener : TraceListener
11 RichTextBox iRichTextBox = null;
13 public RichTextBoxTraceListener(RichTextBox aRichTextBox)
15 iRichTextBox = aRichTextBox;
18 public override void WriteLine(string aString)
20 //Add time stamp and new line characters
21 Write(DateTime.Now.ToString("MM/dd HH:mm:ss.fff: ") + aString + "\r\n");
24 public override void Write(string aString)
26 //Allows iRichTextBox to be updated from different thread
27 if (iRichTextBox.InvokeRequired)
29 // Fire and forget invocation
30 // Using the synchronous variant Invoke tends to result in deadlock here
31 iRichTextBox.BeginInvoke(new MethodInvoker(delegate ()
33 iRichTextBox.Text += aString;
38 iRichTextBox.Text += aString;