Example #1
0
 internal void Run()
 {
     using (_ps)
     {
         bool started;
         lock (_syncRoot)
         {
             started = _ps.Start();
             if (started)
             {
                 try
                 {
                     _name             = _ps.ProcessName;
                     _ps.PriorityClass = ProcessPriorityClass.BelowNormal;
                 }
                 catch (Exception)
                 {
                     // The properties are only accessible if the process is running.
                     // We're actually in a race condition: It might happen that the
                     // process already exited when we access those properties. In
                     // this case, an exception will be thrown.
                 }
                 _state = EToolState.Running;
                 _pool.OnToolSpawned(this);
                 _ps.BeginOutputReadLine();
                 _ps.BeginErrorReadLine();
             }
             else
             {
                 _state = EToolState.StartFailure;
                 _pool.OnFailedToolStart(this);
             }
             _isStarted.Set();
         }
         if (started)
         {
             _ps.WaitForExit();
             lock (_syncRoot)
             {
                 ExitCode = _ps.ExitCode;
                 _state   = EToolState.Exited;
                 _pool.OnToolExited(this);
             }
         }
         _isExited.Set();
     }
 }