Beispiel #1
0
        private String ReadLineAsync()
        {
            String      line   = null;
            AsyncThread thread = AsyncThread.Borrow(() =>
            {
                line = program.StandardOutput.ReadLine();
                outputDone.Set();
            });

            WakeUp();
            timer.Start();
            while (timer.ElapsedMilliseconds <= Settings.TimeLimit)
            {
                bool success = outputDone.WaitOne((int)(Settings.TimeLimit + Settings.ReadTimeMargin - timer.ElapsedMilliseconds));
                if (success)
                {
                    break;                         // success may also be true when the program crashes, see Start()
                }
            }
            timer.Stop();
            Sleep();
            outputDone.Reset();
            AsyncThread.Return(thread, line != null);
            bool potentialCrash = line == null ? true : line.Length == 0;

            if (potentialCrash && program.HasExited)
            {
                throw new Crash();
            }
            if (timer.ElapsedMilliseconds > Settings.TimeLimit)
            {
                throw new Timeout();
            }
            return(line);
        }
Beispiel #2
0
 public void Quit()
 {
     try
     {
         Debug.WriteLine(match.Prefix + "Player " + player.name + " used " + timer.ElapsedMilliseconds + " ms.");
         if (!program.HasExited)
         {
             SendLine("Quit");
             WakeUp();
             if (Settings.KillPrograms)
             {
                 Thread.Sleep(Settings.MillisecondsBeforeKill);
                 Terminate();
             }
             program.WaitForExit();
         }
     }
     finally
     {
         AsyncThread.Return(errorThread, program.HasExited);
     }
 }