4

从 Powershell 命令窗口执行特定脚本时,执行大约需要 2 分钟。使用 System.Management.Automation.Runspaces 从 C#(Windows 服务)执行相同的脚本需要 5 到 6 分钟!从服务中生成新的 powershell.exe 进程会使时间再次下降到 2 分钟。

我还注意到使用 Runspace 时 CPU 使用率更高。

不出所料,几乎所有时间都花在了 Pipeline.Invoke() 中,这并没有让调试问题变得更容易。

我使用的脚本很复杂,而且会做很多事情,因此很难确定这个问题。如何缩小问题范围?

有什么明显的我可能会丢失吗?

4

0 回答 0