|
From: <br...@us...> - 2008-07-06 20:49:46
|
Revision: 291
http://acmcontester.svn.sourceforge.net/acmcontester/?rev=291&view=rev
Author: brus07
Date: 2008-07-06 13:49:54 -0700 (Sun, 06 Jul 2008)
Log Message:
-----------
Tester don't wait testing for receive new data via socket.
Tester don't calculate new data when working on old data (in future response to Mediator about state).
Modified Paths:
--------------
ACMServer/trunk/ACMServer/Tester/Form1.cs
Modified: ACMServer/trunk/ACMServer/Tester/Form1.cs
===================================================================
--- ACMServer/trunk/ACMServer/Tester/Form1.cs 2008-07-06 16:42:12 UTC (rev 290)
+++ ACMServer/trunk/ACMServer/Tester/Form1.cs 2008-07-06 20:49:54 UTC (rev 291)
@@ -8,12 +8,13 @@
using AcmContester.Library.Connector;
using System.IO;
using AcmContester.Library.LibraryExtention;
+using System.Threading;
namespace Tester
{
public partial class Form1 : Form
{
- SocketClient socket;
+ static SocketClient socket;
public Form1()
{
@@ -56,10 +57,44 @@
}
private void DataArrived(string message)
{
- string result = "";
-
UpdateTextLog("\r\n" + message);
+ AddWork(message);
+ }
+ static string source;
+ static object working = 0;
+ Thread thread = new Thread(new ThreadStart(Go));
+ void AddWork(string message)
+ {
+ lock (working)
+ {
+ if ((int)working == 1 || (thread.ThreadState == ThreadState.Running))
+ {
+ UpdateTextLog("\r\n--------- busy ---------");
+ return;
+ }
+ }
+ source = message;
+ onDataArrived += UpdateTextLog;
+ thread = new Thread(new ThreadStart(Go));
+ thread.Start();
+ }
+
+ static void Go()
+ {
+ lock (working)
+ {
+ working = 1;
+ }
+ Testing(source);
+ lock (working)
+ {
+ working = 0;
+ }
+ }
+ static void Testing(string message)
+ {
+ string result;
try
{
result = Checker.Checker.GetResult(message);
@@ -72,11 +107,19 @@
return;
}
- UpdateTextLog("\r\n" + result);
- socket.Send(result);
+ if (onDataArrived != null)
+ {
+ onDataArrived("\r\n" + result);
+ onDataArrived("\r\n--------- free ---------");
+ }
+ //UpdateTextLog("\r\n" + result);
+ lock(socket)
+ socket.Send(result);
}
+ public delegate void DataArrivedDelegate(string s);
+ public static event DataArrivedDelegate onDataArrived;
delegate void UpdateTextLogCallback(string message);
private void UpdateTextLog(string message)
@@ -98,6 +141,7 @@
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
+ thread.Abort();
Disconnect();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|