当前位置: 首页>>代码示例>>C#>>正文


C# Runspace.GetCurrentlyRunningPipeline方法代码示例

本文整理汇总了C#中System.Management.Automation.Runspaces.Runspace.GetCurrentlyRunningPipeline方法的典型用法代码示例。如果您正苦于以下问题:C# Runspace.GetCurrentlyRunningPipeline方法的具体用法?C# Runspace.GetCurrentlyRunningPipeline怎么用?C# Runspace.GetCurrentlyRunningPipeline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.Automation.Runspaces.Runspace的用法示例。


在下文中一共展示了Runspace.GetCurrentlyRunningPipeline方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InvokeOnRunspace

        /// <summary>
        /// Helper method to invoke a PSCommand on a given runspace.  This method correctly invokes the command for 
        /// these runspace cases:
        ///   1. Local runspace.  If the local runspace is busy it will invoke as a nested command.
        ///   2. Remote runspace.
        ///   3. Runspace that is stopped in the debugger at a breakpoint.
        ///   
        /// Error and information streams are ignored and only the command result output is returned.
        /// 
        /// This method is NOT thread safe.  It does not support running commands from different threads on the 
        /// provided runspace.  It assumes the thread invoking this method is the same that runs all other 
        /// commands on the provided runspace.
        /// </summary>
        /// <param name="runspace">Runspace to invoke the command on</param>
        /// <param name="command">Command to invoke</param>
        /// <returns>Collection of command output result objects</returns>
        public static Collection<PSObject> InvokeOnRunspace(PSCommand command, Runspace runspace)
        {
            if (command == null)
            {
                throw new PSArgumentNullException("command");
            }

            if (runspace == null)
            {
                throw new PSArgumentNullException("runspace");
            }

            if ((runspace.Debugger != null) && runspace.Debugger.InBreakpoint)
            {
                // Use the Debugger API to run the command when a runspace is stopped in the debugger.
                PSDataCollection<PSObject> output = new PSDataCollection<PSObject>();
                runspace.Debugger.ProcessCommand(
                    command,
                    output);

                return new Collection<PSObject>(output);
            }

            // Otherwise run command directly in runspace.
            PowerShell ps = PowerShell.Create();
            ps.Runspace = runspace;
            ps.IsRunspaceOwner = false;
            if (runspace.ConnectionInfo == null)
            {
                // Local runspace.  Make a nested PowerShell object as needed.
                ps.SetIsNested(runspace.GetCurrentlyRunningPipeline() != null);
            }
            using (ps)
            {
                ps.Commands = command;
                return ps.Invoke<PSObject>();
            }
        }
开发者ID:40a,项目名称:PowerShell,代码行数:54,代码来源:HostUtilities.cs


注:本文中的System.Management.Automation.Runspaces.Runspace.GetCurrentlyRunningPipeline方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。