一些背景知识:
简而言之,标准SharePoint指南是不同的线程不应使用COM支持的对象,如SPSite
和SPWeb
。这与PowerShell默认使用MTA模式相冲突,在上面引用的Leak Workarounds帖子中进行了验证。一个建议的解决方法是尝试PowerShell 2.0的-STA标志,这似乎应该解决问题;然而,在他的帖子评论Zach建议STA模式是不够的。
这推动了我的COM知识的边缘,所以我希望有人可以帮助我理解......
答案 0 :(得分:2)
最终,只要您使用Powershell 2.0,-STA模式就足够了。原因是在STA模式下,默认运行空间为所有交互式命令(以及脚本)重用单个线程。 Zach在2月份看到的PowerShell版本可能与PowerShell 2.0的当前RC / RTM不同。它可能使用了UseNewThread而不是当前默认值ReUseThread:
PS> [System.Management.Automation.Runspaces.Runspace]::DefaultRunspace
Events : System.Management.Automation.PSLocalEventManager
ThreadOptions : ReuseThread
RunspaceConfiguration : System.Management.Automation.Runspaces.RunspaceConfigForSingleShell
InitialSessionState :
Version : 2.0
RunspaceStateInfo : Opened
RunspaceAvailability : Busy
ConnectionInfo :
ApartmentState : STA
InstanceId : 8d3bfae1-8b64-433d-9ab9-ce640b15f84f
SessionStateProxy : System.Management.Automation.Runspaces.SessionStateProxy
Debugger : System.Management.Automation.Debugger
总之,你在这里很好。他正在讨论的高级技术很可能是如何使用ReUseThread来启动新的运行空间,因为这是-STA的默认线程选项,因此现在是多余的。但是,您可以使用此技术在MTA模式下在单个线程上运行; - )
-Oisin
Microsoft PowerShell MVP