下面的代码在尝试结束invoke时抛出PipelineStoppedException。有人能看出有什么不对劲吗?谢谢。
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.
},
null);
}
}发布于 2010-12-22 23:08:52
按照设计,BeginInvoke会立即返回,所以using子句会关闭,在调用EndInvoke之前处理powershell实例。使用常规的同步调用。您混淆了同步和异步模式。
https://stackoverflow.com/questions/4504873
复制相似问题