/[RomCheater]/trunk/RomCheater.Logging/LogWriter.cs
ViewVC logotype

Diff of /trunk/RomCheater.Logging/LogWriter.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater.Logging/LogWriter.cs	2012/06/05 15:24:43	315
+++ trunk/RomCheater.Logging/LogWriter.cs	2012/06/05 15:35:51	316
@@ -17,10 +17,13 @@
     public partial class LogWriter : UserControl
     {
         private static string LOG_PATH { get { return string.Format(@"{0}\{1}", typeof(LogWriter).Assembly.Location.Replace("RomCheater.Logging.dll", ""), LoggingConstants.AppLogFile); } }
+        private delegate void OnSetLogText(string value, bool invoked);
+        private OnSetLogText HandleSetLogText = null;
         public LogWriter() : this(false) { }
         public LogWriter(bool redirectConsole)
         {
             InitializeComponent();
+            HandleSetLogText += new OnSetLogText(SetLogText);
             this.Log = new LogStream(this);
             this.RedirectConsoleOutput = redirectConsole;
             toolTip1.SetToolTip(btnClearLog, "Clears the Log");
@@ -71,7 +74,9 @@
 
         private void btnClearLog_Click(object sender, EventArgs e) { this.Clear(true); }
         private void btnCopyLogToClipboard_Click(object sender, EventArgs e) { Clipboard.SetText(txtLog.Text); }
-        public void SetLogText(string value)
+
+
+        public void WriteLogToFile(string value)
         {
             FileStream fs = new FileStream(LOG_PATH, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
             StreamWriter writer = new StreamWriter(fs);
@@ -79,14 +84,26 @@
             if (value == Log.NewLine) { writer.Write(System.Environment.NewLine); }
             else { writer.Write(value); }
             writer.Close();
-            txtLog.Text += value;
+        }
+        public void SetLogText(string value) { SetLogText(value, false); }
+        public void SetLogText(string value, bool invoked)
+        {
+            if (!invoked) { WriteLogToFile(value); }
 
-            if (AutoScroll)
+            if (txtLog.InvokeRequired)
             {
-                txtLog.SelectionStart = txtLog.TextLength;
-                txtLog.ScrollToCaret();
-                txtLog.Refresh();
+                this.Invoke(HandleSetLogText, new object[] { value, true });
             }
+            else
+            {
+                txtLog.Text += value;
+                if (AutoScroll)
+                {
+                    txtLog.SelectionStart = txtLog.TextLength;
+                    txtLog.ScrollToCaret();
+                    txtLog.Refresh();
+                }
+            }           
             Thread.Sleep(100);
         }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22