internal void ExecuteCommandAsyncHelper(Pipeline tempPipeline, out Exception exceptionThrown, Executor.ExecutionOptions options) { exceptionThrown = null; Executor currentExecutor = Executor.CurrentExecutor; Executor.CurrentExecutor = this; lock (this.instanceStateLock) { this.pipeline = tempPipeline; } try { try { if ((options & Executor.ExecutionOptions.AddOutputter) > Executor.ExecutionOptions.None && this.parent.OutputFormat == Serialization.DataFormat.Text) { if (tempPipeline.Commands.Count == 1) { tempPipeline.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output); } Command command = new Command("Out-Default", false, true); tempPipeline.Commands.Add(command); } tempPipeline.Output.DataReady += new EventHandler(this.OutputObjectStreamHandler); tempPipeline.Error.DataReady += new EventHandler(this.ErrorObjectStreamHandler); Executor.PipelineFinishedWaitHandle pipelineFinishedWaitHandle = new Executor.PipelineFinishedWaitHandle(tempPipeline); tempPipeline.InvokeAsync(); if ((options & Executor.ExecutionOptions.ReadInputObjects) > Executor.ExecutionOptions.None && this.parent.IsStandardInputRedirected) { WrappedDeserializer wrappedDeserializer = new WrappedDeserializer(this.parent.InputFormat, "Input", this.parent.StandardInReader); while (!wrappedDeserializer.AtEnd) { object obj = wrappedDeserializer.Deserialize(); if (obj == null) { break; } try { tempPipeline.Input.Write(obj); } catch (PipelineClosedException pipelineClosedException) { break; } } wrappedDeserializer.End(); } tempPipeline.Input.Close(); pipelineFinishedWaitHandle.Wait(); if (tempPipeline.PipelineStateInfo.State == PipelineState.Failed && tempPipeline.PipelineStateInfo.Reason != null) { if (this.parent.OutputFormat != Serialization.DataFormat.Text) { this.AsyncPipelineFailureHandler(tempPipeline.PipelineStateInfo.Reason); } else { exceptionThrown = tempPipeline.PipelineStateInfo.Reason; } } } catch (Exception exception1) { Exception exception = exception1; ConsoleHost.CheckForSevereException(exception); exceptionThrown = exception; } } finally { this.parent.ui.ResetProgress(); Executor.CurrentExecutor = currentExecutor; this.Reset(); } }