NuGetConsole.Host.PowerShell.Implementation.RunspaceDispatcher.InvokeCoreAsync C# (CSharp) Method

InvokeCoreAsync() private method

private InvokeCoreAsync ( System.Management.Automation.Runspaces.Pipeline pipeline, IEnumerable inputs ) : void
pipeline System.Management.Automation.Runspaces.Pipeline
inputs IEnumerable
return void
        private void InvokeCoreAsync(Pipeline pipeline, IEnumerable<object> inputs)
        {
            pipeline.StateChanged += (sender, e) =>
            {
                switch (e.PipelineStateInfo.State)
                {
                    case PipelineState.Completed:
                    case PipelineState.Failed:
                    case PipelineState.Stopped:
                        // Release the dispatcher lock
                        Monitor.Exit(_dispatcherLock);
                        break;
                }
            };

            if (inputs != null)
            {
                foreach (var input in inputs)
                {
                    pipeline.Input.Write(input);
                }
            }

            // Take the dispatcher lock and invoke the pipeline
            // REVIEW: This could probably be done in a Task so that we can return to the caller before even taking the dispatcher lock
            Monitor.Enter(_dispatcherLock);
            try
            {
                pipeline.InvokeAsync();
            }
            catch
            {
                // Don't care about the exception, rethrow it, but first release the lock
                Monitor.Exit(_dispatcherLock);
                throw;
            }
        }
    }