From cdfe9754276272ee5a6a6ce455feed8d92f30583 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Sat, 30 May 2009 21:06:51 +0000 Subject: [PATCH] Replaced Control.Invoke() by Control.BeginInvoke() to avoid deadlock when Debug.Print() is called from the finalizing thread. --- Source/Examples/TextBoxTraceListener.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/Examples/TextBoxTraceListener.cs b/Source/Examples/TextBoxTraceListener.cs index b66de856..3167488b 100644 --- a/Source/Examples/TextBoxTraceListener.cs +++ b/Source/Examples/TextBoxTraceListener.cs @@ -3,13 +3,14 @@ using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.Windows.Forms; +using System.Threading; namespace Examples { public class TextBoxTraceListener : TraceListener { - private TextBox _target; - private StringSendDelegate _invokeWrite; + TextBox _target; + StringSendDelegate _invokeWrite; public TextBoxTraceListener(TextBox target) { @@ -20,13 +21,13 @@ namespace Examples public override void Write(string message) { if (_target.Created) - _target.Invoke(_invokeWrite, new object[] { message }); + _target.BeginInvoke(_invokeWrite, new object[] { message }); } public override void WriteLine(string message) { if (_target.Created) - _target.Invoke(_invokeWrite, new object[] { message + Environment.NewLine }); + _target.BeginInvoke(_invokeWrite, new object[] { message + Environment.NewLine }); } private delegate void StringSendDelegate(string message);