Ejemplo n.º 1
0
        private static Yield ExecuteProcess_Helper(string application, string cmdline, Stream input, Stream output, Stream error, Result <int> result)
        {
            // start process
            var proc = new Process();

            proc.StartInfo.FileName               = application;
            proc.StartInfo.Arguments              = cmdline;
            proc.StartInfo.UseShellExecute        = false;
            proc.StartInfo.CreateNoWindow         = true;
            proc.StartInfo.RedirectStandardInput  = (input != null);
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.RedirectStandardError  = true;
            proc.Start();

            // inject input
            if (input != null)
            {
                input.CopyTo(proc.StandardInput.BaseStream, long.MaxValue, new Result <long>(TimeSpan.MaxValue)).WhenDone(_ => {
                    // trying closing the original input stream
                    try {
                        input.Close();
                    } catch { }

                    // try closing the process input pipe
                    try {
                        proc.StandardInput.Close();
                    } catch { }
                });
            }

            // extract output stream
            Result <long> outputDone = proc.StandardOutput.BaseStream.CopyTo(output, long.MaxValue, new Result <long>(TimeSpan.MaxValue));

            // extract error stream
            Result <long> errorDone = proc.StandardError.BaseStream.CopyTo(error, long.MaxValue, new Result <long>(TimeSpan.MaxValue));
            TaskTimer     timer     = TaskTimerFactory.Current.New(result.Timeout, delegate(TaskTimer t) {
                try {
                    // NOTE (steveb): we had to add the try..catch handler because mono throws an exception when killing a terminated process (why? who knows!)

                    proc.Kill();
                } catch { }
            }, null, TaskEnv.New());

            // wait for output and error streams to be done
            yield return(new AResult[] { outputDone, errorDone }.Join());

            int?exitCode = WaitForExit(proc, result.Timeout);

            timer.Cancel();
            proc.Close();
            if (exitCode.HasValue)
            {
                result.Return(exitCode.Value);
            }
            else
            {
                result.Throw(new InvalidOperationException("Unable to access process exit code"));
            }
        }
Ejemplo n.º 2
0
 public void Flush()
 {
     lock (_syncRoot) {
         if (_pendingUpdates > 0)
         {
             _autoFlushTimer.Cancel();
             _pendingUpdates = 0;
             try {
                 _flush(_state, _disposed);
             } catch (Exception e) {
                 _log.Error("flush handler failed", e);
             }
         }
     }
 }
Ejemplo n.º 3
0
 public void Dispose()
 {
     if (_disposed)
     {
         return;
     }
     _disposalLock.ExecuteWithWriteLock(() => {
         _disposed = true;
         _writer.Close();
         _searcher.Close();
         _reader.Close();
         _queue.Dispose();
         if (_commitTimer != null)
         {
             _commitTimer.Cancel();
         }
     });
 }
Ejemplo n.º 4
0
 protected virtual void Refresh(object sender, object e)
 {
     _transTimer.Cancel();
     Refresh();
 }
Ejemplo n.º 5
0
 public void Dispose()
 {
     _isDisposed = true;
     _pollTimer.Cancel();
 }