powershell throws PipelineStoppedException for an async call
Below code throws PipelineStoppedException when it tries to end invoke. Could anybody see anything wrong? Thanks.
        using (PowerShell powershell = PowerShell.Create())
        {                
                powershell.AddScript(script);
                powershell.Runspace = CreateRunspace();
                lock (powershell.Runspace)
                {
                    powershell.BeginInvoke(
                                input,
                                setting,
                                delegate(IAsyncResult result)
                                {                                       
                                  powershell.EndInvoke(result); // throw pipeline stopped exception.                                         
  开发者_JS百科                              },
                               null);
                }
        }
BeginInvoke returns immediately - by design - so the using clause closes, disposing the powershell instance before EndInvoke gets called. Use regular synchronous Invoke. You are mixing up sync and async patterns.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论