From: <br...@us...> - 2008-06-27 09:38:54
|
Revision: 283 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=283&view=rev Author: brus07 Date: 2008-06-27 02:38:51 -0700 (Fri, 27 Jun 2008) Log Message: ----------- Replace updating logTextBox with timer to updating with special function from Windows.Form. Now scrolling to down only when change text in logTextBox. Modified Paths: -------------- ACMServer/trunk/ACMServer/Mediator/Form1.Designer.cs ACMServer/trunk/ACMServer/Mediator/Form1.cs ACMServer/trunk/ACMServer/Mediator/Form1.resx ACMServer/trunk/ACMServer/Tester/Form1.Designer.cs ACMServer/trunk/ACMServer/Tester/Form1.cs ACMServer/trunk/ACMServer/Tester/Form1.resx Modified: ACMServer/trunk/ACMServer/Mediator/Form1.Designer.cs =================================================================== --- ACMServer/trunk/ACMServer/Mediator/Form1.Designer.cs 2008-06-26 22:43:10 UTC (rev 282) +++ ACMServer/trunk/ACMServer/Mediator/Form1.Designer.cs 2008-06-27 09:38:51 UTC (rev 283) @@ -28,14 +28,12 @@ /// </summary> private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); this.button2 = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.button3 = new System.Windows.Forms.Button(); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.textBox2 = new System.Windows.Forms.TextBox(); this.textBox3 = new System.Windows.Forms.TextBox(); - this.timerUpdateTextLog = new System.Windows.Forms.Timer(this.components); this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); this.tabControl1.SuspendLayout(); @@ -99,12 +97,6 @@ this.textBox3.Size = new System.Drawing.Size(343, 190); this.textBox3.TabIndex = 12; // - // timerUpdateTextLog - // - this.timerUpdateTextLog.Enabled = true; - this.timerUpdateTextLog.Interval = 2000; - this.timerUpdateTextLog.Tick += new System.EventHandler(this.timerUpdateTextLog_Tick); - // // tabControl1 // this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -159,7 +151,6 @@ private System.Windows.Forms.StatusStrip statusStrip1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.TextBox textBox3; - private System.Windows.Forms.Timer timerUpdateTextLog; private System.Windows.Forms.TabControl tabControl1; private System.Windows.Forms.TabPage tabPage1; } Modified: ACMServer/trunk/ACMServer/Mediator/Form1.cs =================================================================== --- ACMServer/trunk/ACMServer/Mediator/Form1.cs 2008-06-26 22:43:10 UTC (rev 282) +++ ACMServer/trunk/ACMServer/Mediator/Form1.cs 2008-06-27 09:38:51 UTC (rev 283) @@ -21,7 +21,6 @@ textBox2.Text = s; } - string fullLog = ""; AcmContester.Mediator.Library.MediatorKernel kernel; private void button2_Click(object sender, EventArgs e) @@ -60,23 +59,24 @@ { string s = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString() + ": "; s += message; + UpdateTextLog(s + "\r\n"); + } - lock (fullLog) + delegate void UpdateTextLogCallback(string message); + private void UpdateTextLog(string message) + { + if (this.textBox3.InvokeRequired) { - fullLog += s; - fullLog += "\r\n"; + UpdateTextLogCallback d = new UpdateTextLogCallback(UpdateTextLog); + this.Invoke(d, new object[] { message }); } - } - private void UpdateTextLog() - { - lock (fullLog) + else { - //textBox3.SelectedText = fullLog; - textBox3.Text += fullLog; + textBox3.Text += message; textBox3.Select(textBox3.Text.Length, 0); textBox3.ScrollToCaret(); - fullLog = ""; } + } private void button3_Click(object sender, EventArgs e) @@ -100,10 +100,5 @@ { button2_Click(this, null); } - - private void timerUpdateTextLog_Tick(object sender, EventArgs e) - { - UpdateTextLog(); - } } } \ No newline at end of file Modified: ACMServer/trunk/ACMServer/Mediator/Form1.resx =================================================================== --- ACMServer/trunk/ACMServer/Mediator/Form1.resx 2008-06-26 22:43:10 UTC (rev 282) +++ ACMServer/trunk/ACMServer/Mediator/Form1.resx 2008-06-27 09:38:51 UTC (rev 283) @@ -120,7 +120,4 @@ <metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <value>17, 17</value> </metadata> - <metadata name="timerUpdateTextLog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> - <value>300, 17</value> - </metadata> </root> \ No newline at end of file Modified: ACMServer/trunk/ACMServer/Tester/Form1.Designer.cs =================================================================== --- ACMServer/trunk/ACMServer/Tester/Form1.Designer.cs 2008-06-26 22:43:10 UTC (rev 282) +++ ACMServer/trunk/ACMServer/Tester/Form1.Designer.cs 2008-06-27 09:38:51 UTC (rev 283) @@ -38,7 +38,6 @@ this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); this.timer1 = new System.Windows.Forms.Timer(this.components); - this.timerUpdateTextLog = new System.Windows.Forms.Timer(this.components); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); // @@ -123,12 +122,6 @@ this.timer1.Enabled = true; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // - // timerUpdateTextLog - // - this.timerUpdateTextLog.Enabled = true; - this.timerUpdateTextLog.Interval = 400; - this.timerUpdateTextLog.Tick += new System.EventHandler(this.timerUpdateTextLog_Tick); - // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -163,7 +156,6 @@ private System.Windows.Forms.StatusStrip statusStrip1; private System.Windows.Forms.Timer timer1; private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1; - private System.Windows.Forms.Timer timerUpdateTextLog; } } Modified: ACMServer/trunk/ACMServer/Tester/Form1.cs =================================================================== --- ACMServer/trunk/ACMServer/Tester/Form1.cs 2008-06-26 22:43:10 UTC (rev 282) +++ ACMServer/trunk/ACMServer/Tester/Form1.cs 2008-06-27 09:38:51 UTC (rev 283) @@ -14,7 +14,7 @@ public partial class Form1 : Form { SocketClient socket; - string fullLog = ""; + public Form1() { InitializeComponent(); @@ -58,15 +58,10 @@ { string result = ""; - //textBox1.Text += "\r\n" + message; - lock (fullLog) - { - fullLog += "\r\n"; - fullLog += message; - } + UpdateTextLog("\r\n" + message); + try { - result = Checker.Checker.GetResult(message); } catch (Exception ex) @@ -77,15 +72,30 @@ return; } - //textBox1.Text += "\r\n\t-> " + result; - lock (fullLog) + UpdateTextLog("\r\n" + result); + socket.Send(result); + } + + + + delegate void UpdateTextLogCallback(string message); + private void UpdateTextLog(string message) + { + if (this.textBox1.InvokeRequired) { - fullLog += "\r\n\t->"; - fullLog += result; + UpdateTextLogCallback d = new UpdateTextLogCallback(UpdateTextLog); + this.Invoke(d, new object[] { message }); } - socket.Send(result); + else + { + textBox1.Text += message; + textBox1.Select(textBox1.Text.Length, 0); + textBox1.ScrollToCaret(); + } + } + private void Form1_FormClosing(object sender, FormClosingEventArgs e) { Disconnect(); @@ -113,7 +123,7 @@ } catch (Exception) { - fullLog += "\r\n\tLogFile can't open. Working without logging to LogFile."; + UpdateTextLog("\r\n\tLogFile can't open. Working without logging to LogFile."); } } @@ -123,22 +133,5 @@ textBox1.ScrollToCaret(); } - private void UpdateTextLog() - { - lock (fullLog) - { - //textBox3.SelectedText = fullLog; - textBox1.Text += fullLog; - textBox1.Select(textBox1.Text.Length, 0); - textBox1.ScrollToCaret(); - fullLog = ""; - } - } - - private void timerUpdateTextLog_Tick(object sender, EventArgs e) - { - UpdateTextLog(); - } - } } \ No newline at end of file Modified: ACMServer/trunk/ACMServer/Tester/Form1.resx =================================================================== --- ACMServer/trunk/ACMServer/Tester/Form1.resx 2008-06-26 22:43:10 UTC (rev 282) +++ ACMServer/trunk/ACMServer/Tester/Form1.resx 2008-06-27 09:38:51 UTC (rev 283) @@ -123,7 +123,4 @@ <metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <value>127, 17</value> </metadata> - <metadata name="timerUpdateTextLog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> - <value>210, 17</value> - </metadata> </root> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |