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")); } }
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); } } } }
public void Dispose() { if (_disposed) { return; } _disposalLock.ExecuteWithWriteLock(() => { _disposed = true; _writer.Close(); _searcher.Close(); _reader.Close(); _queue.Dispose(); if (_commitTimer != null) { _commitTimer.Cancel(); } }); }
protected virtual void Refresh(object sender, object e) { _transTimer.Cancel(); Refresh(); }
public void Dispose() { _isDisposed = true; _pollTimer.Cancel(); }